Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created February 1, 2017 21:52
Show Gist options
  • Save mwotton/f89d82f0e38e1b8fef0d0500485e7912 to your computer and use it in GitHub Desktop.
Save mwotton/f89d82f0e38e1b8fef0d0500485e7912 to your computer and use it in GitHub Desktop.
module Marick where
maybe : b -> (a -> b) -> Maybe a -> b
maybe x f m =
case m of
Nothing -> x
Just y -> f y
type Model = Model
type Form = Form
type Animal = Animal
type Op = CancelEdits
| StartSavingEdits
upsertAnimal : Animal -> Model -> Model
upsertAnimal _ m = m
originalAnimal : Form -> Maybe Animal
originalAnimal Form = Just Animal
noCmd : Model -> Model
noCmd m = m
id : a -> a
id x = x
runOp : Model -> Form -> Op -> Model
runOp model form op =
let original = originalAnimal form in
case op of
CancelEdits -> model |> maybe id upsertAnimal original |> noCmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment