Skip to content

Instantly share code, notes, and snippets.

@snuxoll
Last active April 12, 2016 17:08
Show Gist options
  • Save snuxoll/8576568622bba1add260502b35048316 to your computer and use it in GitHub Desktop.
Save snuxoll/8576568622bba1add260502b35048316 to your computer and use it in GitHub Desktop.
Railway
type Result<'TOk,'TError> =
| Ok of 'TOk
| Error of 'TError
let bind fn =
function
| Ok r -> fn r
| Error e -> Error e
let (>>=) x fn =
bind fn x
let test1 x =
Ok x
let test2 x =
if x <> 0 then Ok x else Error x
let test3 x =
if x <> 1 then Ok x else Error x
let result = 0 |> test1 >>= test2 >>= test3 // will never get to test3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment