Slide 1

Slide 1 text

Elm (plus Angular2/RxJs) Jon Kelly Twitter @jsnightowl Email [email protected] Github jkbits1

Slide 2

Slide 2 text

Why Elm? In how many ways can JavaScript crash? (and I’m a fan!)

Slide 3

Slide 3 text

What’s different with Elm All the jargon you may have heard (and more)  Immutability  Pure functions  Compiled code  Uni-directional data flow (any redux fans here?) btw, it runs pretty fast

Slide 4

Slide 4 text

FP background  Immutability - not always so fixed  Compiled code - not all languages, e.g. Lisp

Slide 5

Slide 5 text

Elm has real benefits This UI is straightforward to code and reason about Basic framework – 20 lines of code

Slide 6

Slide 6 text

Overview Elm code basics Elm front-end DEMO! Time travel debugging Elm - uni-directional design Bonus - solutions in Angular2/RxJs app (if we get the time)

Slide 7

Slide 7 text

Elm code Let’s start small and work forwards

Slide 8

Slide 8 text

Elm code two = 2

Slide 9

Slide 9 text

Elm code timesTwo x = x * two

Slide 10

Slide 10 text

Elm code timesTwo x = x * two timesTwo 2 = 4

Slide 11

Slide 11 text

Elm code timesTwo2 = (*) two

Slide 12

Slide 12 text

Elm code timesTwo2 = (*) two timesTwo2 2 = 4

Slide 13

Slide 13 text

Elm code - currying timesTwice x y = two * x * y timesTwice 3 4 = 24 x = timesTwice 3 = ?? x 4 = 24

Slide 14

Slide 14 text

Types The usual num/int, float, string, bool Suspects Lists like arrays Any length – can only store a single type Tuples like, er, multiples ? Fixed length – may store multiple types Records a bit object-y and a bit duck type-y

Slide 15

Slide 15 text

Lists - real quick Build [1,2,3] like this 1:: 2 :: 3 :: [] Pass as params : xs – entire list x:xs (destructuring like ES6) x is “head”, xs is “tail” NOTE - access anything after head – takes longer TL;DR – Elm functions designed to work with head of list as much as possible

Slide 16

Slide 16 text

Elm code listTimesTwo xs = List.map (\x -> timesTwo x) xs

Slide 17

Slide 17 text

Elm code listTimesTwo = List.map (\x -> timesTwo x)

Slide 18

Slide 18 text

Elm code - tuples timesTwice (x, y) = two * x * y timesTwice (3, 4) = 24 anotherTwice (x, y) = (x * two, y * two) anotherTwice (5,7) = (10, 14)

Slide 19

Slide 19 text

Demo Send data to and receives data from JS code

Slide 20

Slide 20 text

Basic app It is still a complete Elm program

Slide 21

Slide 21 text

Http client Send data to and receives data from JS code

Slide 22

Slide 22 text

Elm works with JS Send data to and receives data from JS code

Slide 23

Slide 23 text

Angular2/RxJs Compiled code - some Uni-directional data flow - possible http://rxmarbles.com/#map

Slide 24

Slide 24 text

RxJs Makes inputs into streams Streams flow into each other They can be cancelled (easily)

Slide 25

Slide 25 text

Resources Code: https://github.com/jkbits1/HaskellElmTalk Demos online: https://haskell-elm-talk.herokuapp.com (repo — https://github.com/jkbits1/talkUI) Elm Documentation: http://elm-lang.org http://guide.elm-lang.org

Slide 26

Slide 26 text

Thank you! Jon Kelly Twitter @jsnightowl Email [email protected] Github jkbits1