SlideShare a Scribd company logo
Reactive Programming in the Browser
Luka Jacobowitz
Agenda
1. Intro to Scala.js and PureScript
2. What exactly is Reactive Programming?
3. Why use Reactive Programming?
4. Live Coding session!
Scala.js
● First appeared in 2013
● Simple Scala to JavaScript compiler
● Can compile almost Scala code without any
changes to existing code
PureScript
● First appeared in 2013
● Strongly inspired by Haskell
● Purely Functional
● Built explicitly for the Browser/JavaScript
environment
Similarities - Function composition
Scala
List(1,2,3) map (_ + 1) filter (_ > 3)
val plus3: Int => Int = (_ + 3)
val plus3Times4 = plus3 >>> (_ * 4)
PureScript
[1,2,3] # map (_ + 1) # filter (_ > 3)
plus3 = (_ + 3)
plus3Times4 = plus3 >>> (_ * 4)
Similarities - ADTs and Pattern Matching
Scala
sealed trait Maybe[+T]
case class Just[T](t: T) extends
Maybe[T]
case object Nada extends
Maybe[Nothing]
x match {
case Just(a) => ...
case Nada => ...
}
PureScript
data Maybe a = Just a | Nada
case x of
(Just a) -> ...
Nada -> ...
Similarities - Monadic comprehensions
Scala
for {
z <- 1 to 20
y <- 1 to z
x <- 1 to y
if x * x + y * y == z * z
} yield (x, y, z)
PureScript
do
z <- 1 .. 20
y <- 1 .. z
x <- 1 .. y
guard $ x * x + y * y == z * z
pure [x, y, z]
Similarities - Higher Kinded Types
Scala
trait Functor[F[_]] {
def map[A, B](f: A => B)
(fa: F[A]): F[B]
}
PureScript
class Functor f where
map :: forall a b. (a -> b)
-> f a
-> f b
Differences
Scala
● Inheritance (can make working
with JS APIs easier)
● Allows partial application of any
parameter
● Needs a runtime environment
● Larger tool/library ecosystem
● Implicits
● String interpolation
● Supports Dynamic typing
PureScript
● Guarantees referential
transparency
● Functions are all curried by
default
● JS semantics
● Eff optimizes out calls to bind
● ST compiles to JS variable
● Hindley-Milner Inference
● Nested Record Updates
● Row Polymorphism
How do we develop user interfaces with pure
functional programming?
Reactive Programming
Reactive programming is programming with asynchronous data streams.
How is that useful?
How is that useful?
Let’s check out some code!
OutWatch
A small library with 3 design goals
● Updating DOM efficiently without
sacrificing abstraction => Virtual DOM
● Handling subscriptions automatically
● Removing or restricting the need for
Higher Order Observables
OutWatch
Scala
val logComponent: VNode = div(
h2("Input here"),
input(inputString → loggingSink)
)
PureScript
logComponent :: forall e.
VDom (console :: CONSOLE | e)
logComponent =
div
[ h2[ text "Input here" ]
, input[inputString ⇒ loggingSink]
]
More code!
Thank you for listening!
You can find out more at http://outwatch.github.io. Or check out my twitter
@LukaJacobowitz and my Blog http://lukajcb.github.io/blog

More Related Content

PDF
Building a Tagless Final DSL for WebGL
PPTX
Lua Study Share
PPT
jimmy hacking (at) Microsoft
KEY
Scala clojure techday_2011
PDF
Js interpreter interpreted
PPTX
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
PDF
Programming Languages: some news for the last N years
PPTX
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Building a Tagless Final DSL for WebGL
Lua Study Share
jimmy hacking (at) Microsoft
Scala clojure techday_2011
Js interpreter interpreted
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Programming Languages: some news for the last N years
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)

What's hot (20)

PPTX
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
PDF
Haskell for data science
PPTX
Java 8 stream and c# 3.5
PDF
PPTX
PDF
Python to scala
PDF
Clojure intro
PDF
Functional Programming and Ruby
PPT
C++ Returning Objects
PDF
C# 4.0 dynamic
PDF
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
PDF
05. haskell streaming io
PPT
My first experience with lambda expressions in java
PPTX
PDF
Altitude San Francisco 2018: WebAssembly Tools & Applications
PDF
Cocoaheads Meetup / Alex Zimin / Swift magic
PDF
Kotlin DSLs
PPTX
Property Based Tesing
PDF
使用.NET构建轻量级分布式框架
PPTX
To Lombok or not to Lombok | J-Fall 2019
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
Haskell for data science
Java 8 stream and c# 3.5
Python to scala
Clojure intro
Functional Programming and Ruby
C++ Returning Objects
C# 4.0 dynamic
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
05. haskell streaming io
My first experience with lambda expressions in java
Altitude San Francisco 2018: WebAssembly Tools & Applications
Cocoaheads Meetup / Alex Zimin / Swift magic
Kotlin DSLs
Property Based Tesing
使用.NET构建轻量级分布式框架
To Lombok or not to Lombok | J-Fall 2019
Ad

Similar to Reactive Programming in the Browser feat. Scala.js and PureScript (20)

PDF
Reactive meetup 0 copy
PDF
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
PDF
Reactive Programming in the Browser feat. Scala.js and Rx
PPTX
Luis Atencio on RxJS
PDF
Reactive programming and RxJS
PPTX
Functional programming, TypeScript and RXJS
PDF
Functional programming is the most extreme programming
PDF
Intro to Functional Reactive Programming In Scala
PPTX
PDF
Buy ebook Functional Reactive Programming 1st Edition Stephen Blackheath chea...
PDF
Scala Programming Introduction
KEY
Scala: functional programming for the imperative mind
PDF
Architecture for scalable Angular applications
PPTX
Reactive programming every day
PDF
Scala Days Highlights | BoldRadius
PPTX
Scala meetup Kyiv slides 20171215
PDF
No more promises lets RxJS 2 Edit
PPTX
Reactive programming
PDF
Functional Reactive Programming in Clojurescript
PDF
Functional Programming #FTW
Reactive meetup 0 copy
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
Reactive Programming in the Browser feat. Scala.js and Rx
Luis Atencio on RxJS
Reactive programming and RxJS
Functional programming, TypeScript and RXJS
Functional programming is the most extreme programming
Intro to Functional Reactive Programming In Scala
Buy ebook Functional Reactive Programming 1st Edition Stephen Blackheath chea...
Scala Programming Introduction
Scala: functional programming for the imperative mind
Architecture for scalable Angular applications
Reactive programming every day
Scala Days Highlights | BoldRadius
Scala meetup Kyiv slides 20171215
No more promises lets RxJS 2 Edit
Reactive programming
Functional Reactive Programming in Clojurescript
Functional Programming #FTW
Ad

More from Luka Jacobowitz (11)

PDF
Monoids, Monoids, Monoids - ScalaLove 2020
PDF
Monoids, monoids, monoids
PDF
Testing in the World of Functional Programming
PDF
Up and Running with the Typelevel Stack
PDF
Principled Error Handling - Scalapeño
PDF
Principled Error Handling with FP
PDF
Oh, All the things you'll traverse
PDF
Advanced Tagless Final - Saying Farewell to Free
PDF
Traversals for all ocasions
PDF
What Referential Transparency can do for you
PDF
Scala UA 2017
Monoids, Monoids, Monoids - ScalaLove 2020
Monoids, monoids, monoids
Testing in the World of Functional Programming
Up and Running with the Typelevel Stack
Principled Error Handling - Scalapeño
Principled Error Handling with FP
Oh, All the things you'll traverse
Advanced Tagless Final - Saying Farewell to Free
Traversals for all ocasions
What Referential Transparency can do for you
Scala UA 2017

Recently uploaded (20)

PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
cuic standard and advanced reporting.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
GamePlan Trading System Review: Professional Trader's Honest Take
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Modernizing your data center with Dell and AMD
Chapter 3 Spatial Domain Image Processing.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
cuic standard and advanced reporting.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
Understanding_Digital_Forensics_Presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....

Reactive Programming in the Browser feat. Scala.js and PureScript

  • 1. Reactive Programming in the Browser Luka Jacobowitz
  • 2. Agenda 1. Intro to Scala.js and PureScript 2. What exactly is Reactive Programming? 3. Why use Reactive Programming? 4. Live Coding session!
  • 3. Scala.js ● First appeared in 2013 ● Simple Scala to JavaScript compiler ● Can compile almost Scala code without any changes to existing code
  • 4. PureScript ● First appeared in 2013 ● Strongly inspired by Haskell ● Purely Functional ● Built explicitly for the Browser/JavaScript environment
  • 5. Similarities - Function composition Scala List(1,2,3) map (_ + 1) filter (_ > 3) val plus3: Int => Int = (_ + 3) val plus3Times4 = plus3 >>> (_ * 4) PureScript [1,2,3] # map (_ + 1) # filter (_ > 3) plus3 = (_ + 3) plus3Times4 = plus3 >>> (_ * 4)
  • 6. Similarities - ADTs and Pattern Matching Scala sealed trait Maybe[+T] case class Just[T](t: T) extends Maybe[T] case object Nada extends Maybe[Nothing] x match { case Just(a) => ... case Nada => ... } PureScript data Maybe a = Just a | Nada case x of (Just a) -> ... Nada -> ...
  • 7. Similarities - Monadic comprehensions Scala for { z <- 1 to 20 y <- 1 to z x <- 1 to y if x * x + y * y == z * z } yield (x, y, z) PureScript do z <- 1 .. 20 y <- 1 .. z x <- 1 .. y guard $ x * x + y * y == z * z pure [x, y, z]
  • 8. Similarities - Higher Kinded Types Scala trait Functor[F[_]] { def map[A, B](f: A => B) (fa: F[A]): F[B] } PureScript class Functor f where map :: forall a b. (a -> b) -> f a -> f b
  • 9. Differences Scala ● Inheritance (can make working with JS APIs easier) ● Allows partial application of any parameter ● Needs a runtime environment ● Larger tool/library ecosystem ● Implicits ● String interpolation ● Supports Dynamic typing PureScript ● Guarantees referential transparency ● Functions are all curried by default ● JS semantics ● Eff optimizes out calls to bind ● ST compiles to JS variable ● Hindley-Milner Inference ● Nested Record Updates ● Row Polymorphism
  • 10. How do we develop user interfaces with pure functional programming?
  • 11. Reactive Programming Reactive programming is programming with asynchronous data streams.
  • 12. How is that useful?
  • 13. How is that useful?
  • 14. Let’s check out some code!
  • 15. OutWatch A small library with 3 design goals ● Updating DOM efficiently without sacrificing abstraction => Virtual DOM ● Handling subscriptions automatically ● Removing or restricting the need for Higher Order Observables
  • 16. OutWatch Scala val logComponent: VNode = div( h2("Input here"), input(inputString → loggingSink) ) PureScript logComponent :: forall e. VDom (console :: CONSOLE | e) logComponent = div [ h2[ text "Input here" ] , input[inputString ⇒ loggingSink] ]
  • 18. Thank you for listening! You can find out more at http://outwatch.github.io. Or check out my twitter @LukaJacobowitz and my Blog http://lukajcb.github.io/blog