Skip to content

Instantly share code, notes, and snippets.

@coreyhaines coreyhaines/Flow.elm
Last active Dec 13, 2019

Embed
What would you like to do?
General workflow-management
module Flow exposing (Flow(..), map, withDefault, mapDefault, view, update)
import Html
type Flow state
= NotRunning
| Running state
map : (state -> state') -> Flow state -> Flow state'
map f flow =
case flow of
NotRunning ->
NotRunning
Running state ->
Running <| f state
withDefault : state -> Flow state -> state
withDefault default flow =
case flow of
NotRunning ->
default
Running state ->
state
mapDefault : state' -> (state -> state') -> Flow state -> state'
mapDefault default fn flow =
map fn flow
|> withDefault default
view : (state -> Html.Html msg) -> Flow state -> Html.Html msg
view viewFn flow =
mapDefault (Html.text "") viewFn flow
update : (state -> ( Flow state, Cmd msg )) -> Flow state -> ( Flow state, Cmd msg)
update fn flow =
mapDefault ( flow, Cmd.none ) fn flow
@MarkFarmiloe

This comment has been minimized.

Copy link

MarkFarmiloe commented Apr 10, 2017

Nice, but what is the Irn module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.