krzysztof-w
8/26/2017 - 8:34 PM

GenServer.elm

module SingletonIncrementer exposing (..)

import Platform exposing (Task(..))
import Task


cast :
    (a -> msg)
    -> (a -> state -> state)
    -> Task Never ()
cast msg response =
    Debug.crash "Crash"


call :
    (a -> msg)
    -> (a -> state -> ( return, state ))
    -> Task Never return
call msg =
    Debug.crash "Crash"


type GenServerResponse reply state
    = Reply reply state
    | Noreply state
    | Stop


type GenServerAction cast call
    = Cast cast
    | Call call



-- After this line everything is defined by hand


type Cast
    = Add Int
    | Increment ()
    | Decrement ()
    | Reset ()


type Call
    = Get ()


add a =
    cast Add (\msg state -> msg + state)


increment =
    cast Increment (\_ state -> state + 1)


decrement =
    cast Decrement (\_ state -> state - 1)


reset =
    cast Reset (\_ state -> 0)


get =
    call Get (\_ state -> ( state, state ))


------ After this line only tests are defined


testFlow =
    reset
        |> Task.andThen (always increment)
        |> Task.andThen (always increment)
        |> Task.andThen (always decrement)
        |> Task.andThen (always get)
        |> Task.map (\int -> int + 1)