Skip to content

Instantly share code, notes, and snippets.

@yukitos
Last active August 29, 2015 14:05
Show Gist options
  • Save yukitos/f1b16c8b96824e59c2aa to your computer and use it in GitHub Desktop.
Save yukitos/f1b16c8b96824e59c2aa to your computer and use it in GitHub Desktop.
let values = [ 1;2;3;2;3;1 ]
let f y x =
if x = y then Choice2Of2 1
else if x < y then Choice1Of2 2
else Choice2Of2 3
let ``all values are Choice1Of2`` =
values
|> List.map (f 4)
let sequence1 =
``all values are Choice1Of2``
|> FSharpx.Choice.sequence
let ``contains Choice2Of2`` =
values
|> List.map (f 2)
let sequence2 =
``contains Choice2Of2``
|> FSharpx.Choice.sequence
val values : int list = [1; 2; 3; 2; 3; 1]
val f : y:'a -> x:'a -> Choice<int,int> when 'a : comparison
val ( all values are Choice1Of2 ) : Choice<int,int> list =
[Choice1Of2 2; Choice1Of2 2; Choice1Of2 2; Choice1Of2 2; Choice1Of2 2;
Choice1Of2 2]
val sequence1 : Choice<int list,int> = Choice1Of2 [2; 2; 2; 2; 2; 2]
val ( contains Choice2Of2 ) : Choice<int,int> list =
[Choice1Of2 2; Choice2Of2 1; Choice2Of2 3; Choice2Of2 1; Choice2Of2 3;
Choice1Of2 2]
val sequence2 : Choice<int list,int> = Choice2Of2 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment