SlideShare a Scribd company logo

Functional Reactive Programming

Functional Reactive Programming - Presentasjon fra på fagkveld hos Webstep Fokus

1 of 27
Download to read offline
Functional
Reactive
Programming
Reactive?
Å reagere på asynkrone hendelser
Web applikasjon er reactive:

Mouse clicks, key presses, async data fra
server
Hvordan være reactive?
State brukes til å representere systemet på et gitt
tidspunkt
Vanskelig med feilhåndtering
Bruk av mye state fører til kompleks spaghettikode
Functional Reactive
Programming to the
rescue!
Functional Reactive Programming
http://stackoverflow.com/questions/1028250/what-is-functional-reactive-programming/1030631#1030631
Datatypes som representerer en verdi over tid
med verktøy fra funksjonell programmering.
• Composition
• Event streams
• Tools
Functional Reactive Programming

Recommended

The algebra of library design
The algebra of library designThe algebra of library design
The algebra of library designLeonardo Borges
 
What is Reactive programming?
What is Reactive programming?What is Reactive programming?
What is Reactive programming?Kevin Webber
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsLeonardo Borges
 
02 - [ASP.NET Core] ASP.NET Core MVC
02 - [ASP.NET Core] ASP.NET Core MVC 02 - [ASP.NET Core] ASP.NET Core MVC
02 - [ASP.NET Core] ASP.NET Core MVC Cellenza
 
Microservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationMicroservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationKevin Webber
 
Real world functional reactive programming
Real world functional reactive programmingReal world functional reactive programming
Real world functional reactive programmingEric Polerecky
 
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Angular, ASP.NET Core, and Visual Studio Code - Oh My!Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Angular, ASP.NET Core, and Visual Studio Code - Oh My!Aaron Marisi
 

More Related Content

Featured

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Functional Reactive Programming

  • 2. Reactive? Å reagere på asynkrone hendelser Web applikasjon er reactive:
 Mouse clicks, key presses, async data fra server
  • 3. Hvordan være reactive? State brukes til å representere systemet på et gitt tidspunkt Vanskelig med feilhåndtering Bruk av mye state fører til kompleks spaghettikode
  • 6. Datatypes som representerer en verdi over tid med verktøy fra funksjonell programmering. • Composition • Event streams • Tools Functional Reactive Programming
  • 7. Functional Event streams er Immutable
 
 Operasjoner på en event stream returnerer alltid en ny event stream.
  • 8. Event streams En sekvens av events sortert i tid En event stream kan sende ut: • Values • Errors • Completed signal Click Click Click Click X Time CompletedError
  • 9. Event streams Å lytte på en stream kalles subscribing. Fungerer som en asynkron callback akkurat som promises! Observer Design Pattern • Subject: Event Stream • Observer: Subscriber
  • 10. Event streams ALT kan være en stream! 
 DOM events, user input, properties, promises Streams kan være input til andre streams Streams kan filtreres, slås sammen og manipuleres
  • 11. Reactive Extensions (Rx*): 
 .NET, Java, Scala, Clojure, JavaScript, Ruby, Python, C++, Objective-C/Cocoa, Groovy Bacon.js Elm - A functional reactive language Rammeverk (Tools)
  • 12. Bacon.js “Turns your event spaghetti into clean and declarative feng shui bacon"
  • 13. Lage en event stream • $(“#myDiv").asEventStream("click") • Bacon.fromPromise(…) • Bacon.fromEventTarget(..) • Bacon.fromCallback(…), Bacon.fromNodeCallback(…) • Bacon.fromPoll(..) • Bacon.once(…), Bacon.never(), Bacon.later(…) • Bacon.fromArray(…) • Bacon.interval(…) • Bacon.sequentially(…) • Bacon.repeatedly(…) • new Bacon.EventStream()
  • 14. Transformere en event stream ved å bruke funksjoner som map, scan, fold, flatMap
  • 15. Transformere event streams map(f)
 Utfører en funksjon f på alle verdier i en event stream. scan(seed, f)
 Som map(f) men med en seed-verdi som sendes inn i neste funksjon. fold(seed, f) (reduce)
 Som scan, men fold sender bare ut sluttverdien. flatMap(f)
 Som map(f), men hvor f returnerer event streams. flatMap vil flate ut alle event streams returnert fra f og returnere disse som én event stream.
  • 16. Påvirk når verdier kommer ut av en 
 event stream med funksjoner som debounce, debounceImmediate, throttle, bufferingThrottle, delay, slidingWindow
  • 17. Filtrer event streams med funksjoner som filter, take, skip, takeWhile, skipWhile, takeUntil, skipUntil
  • 18. Slå sammen streams med funksjoner som merge, zip og concat
  • 20. Thinking reactive • Alt kan representeres som en stream • Sett sammen og manipuler streams til bedre spesialiserte streams til formålet • GUI-rendring i subscribe-funksjon
  • 21. Demo - click events
  • 22. Demo - drag drop Hva er gjør man når man drar en ting rundt på skjermen? 1. Start: Mouse down 2. Flytt: Mouse move 3. Stop: Mouse up
  • 23. Demo - Konami Code Alle nettsider med respekt for seg selv må ha innebygde easter eggs. ↑ ↑ ↓ ↓ ← → ← → B A
  • 24. Fordeler med FRP • Abstraherer bort implementasjonsdetaljer • Mindre state • Immutable event streams gjør det lett å gjenbruke • Forutsigbar kode
  • 25. Dette høres ut som noe hipster tøys
  • 27. Dette ble litt mye å huske på Koden fra demo https://github.com/olavhaugen/fagkveld-frp The introduction to Reactive Programming 
 you've been missing 
 
 https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
 (Bare google: “Reactive programming”) Bacon.js https://github.com/baconjs/bacon.js/
 http://baconjs.blogspot.fi/ RxMarbles http://rxmarbles.com/