Skip to content

Instantly share code, notes, and snippets.

@Chadtech
Created September 1, 2018 23:20
Show Gist options
  • Save Chadtech/d8cd73ecbea57ed752c81c17917179fa to your computer and use it in GitHub Desktop.
Save Chadtech/d8cd73ecbea57ed752c81c17917179fa to your computer and use it in GitHub Desktop.
type alias Fields =
{ data1 : Maybe String
, data2 : Maybe Int
, data3 : Maybe Bool
}
type alias Submission =
{ data1 : String
, data2 : Int
, data3 : Bool
}
type Error
= Error
validate : Fields -> Result Error Submission
validate fields =
Submission
|> Ok
|> give fields.data1
|> give fields.data2
|> give fields.data3
give : Maybe a -> Result Error (a -> b) -> Result Error b
give maybeValue result =
case maybeValue of
Just value ->
case result of
Ok ctor ->
Ok (ctor value)
Err err ->
Err err
Nothing ->
Err Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment