elm,

a delightful language

for learning

functional programming

@kajetansw

kajetan.dev

Kajetan Świątek

👨‍🎨 Front-end developer

🇵🇱 Wrocław

Why should you be interested in FP?

What is Elm?

Why should you at least try it?

Other FP languages that compile to JS

Elm vs TypeScript

Why should you be interested in FP?

1

pure functions

2

IMMUTABILITY

3

easier testing

4

constant growth

5

BROADENS YOUR MIND

What is Elm?

What is Elm?

why should you try it?

ADVANTAGES OF THE FP WORLD

1

Immutability

2

PURE FUNCTIONS

3

EASIER TO TEST

4

BROADENS YOUR MIND

5

CONSTANT GROWTH

SMALL(ISH) LEARNING CURVE FOR JS DEVELOPERS

Easier*

* subjective; relatively, in comparison 

Harder*

THE ELM architecture

Model

View

Update

render

message

Elm runtime

command

message

THE ELM ARCHITECTURE

type alias Model = Int

init : Model
init = 0
view : Model -> Html Msg
view model =
    div []
        [ button [ onClick Decrement ] [ text "-" ]
        , text (String.fromInt model)
        , button [ onClick Increment ] [ text "+" ]
        ]
type Msg
    = Increment
    | Decrement


update : Msg -> Model -> Model
update msg model =
    case msg of
        Increment ->
            model + 1

        Decrement ->
            model - 1

Model

View

Update

render

message

no runtime errors.

getHero : String -> Cmd Msg
getHero url =
    Http.get
        { url = url
        , expect = Http.expectJson HeroReceived heroDecoder
        }

Fetching data via HTTP requires data decoder

no 'null' or 'undefined'.

type Maybe a
    = Just a
    | Nothing

sanitize : String -> Maybe Int
sanitize input =
  String.toInt (String.trim input)
  
getDefault : Maybe Int -> Int
getDefault input = 
  case input of 
    Just i -> i
    Nothing -> 0

Sanitizing user's input

GREAT COMPILER ERROR MESSAGES

elm vs typescript

elm vs typescript

*

*

**

*

*    disadvantage comes from the nature of JavaScript

Prevents runtime data inconsistency

(API changes, etc.)

No `null` and `undefined`

Immutability

No `any` or `unknown` type

Prevents poor typing from 3rd-party libraries

Easy to adopt in existing project

**  mutability can be good when used properly (e.g. when comes to the performance)

elm vs typescript

fp libraries for ts

fp-ts
@effect-ts/core

other fp languages that compile to js

other fp languages that compile to js

examples of elm apps

elm-survey-app

elm learning resources

Thank you!

✋😎

@kajetansw

kajetan.dev

Made with Slides.com