Created
February 1, 2017 21:52
-
-
Save mwotton/f89d82f0e38e1b8fef0d0500485e7912 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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