Skip to content

Instantly share code, notes, and snippets.

@wende
Created August 26, 2017 20:34
Show Gist options
  • Save wende/51c848e4184a283ca5c8ec4da43cf4cd to your computer and use it in GitHub Desktop.
Save wende/51c848e4184a283ca5c8ec4da43cf4cd to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment