7 people like it.
Like the snippet!
Seq.partition
A partition function on sequences, like List.partition and Array.partition, but yields elements in either partition on demand. Suitable as an extension to Seq.
1:
2:
3:
4:
5:
6:
7:
8:
9:
|
let partition condition values =
let pairs = seq {
for i in values do
if condition i then
yield Some(i), None
else
yield None, Some(i) }
pairs |> Seq.choose fst, pairs |> Seq.choose snd
|
val partition : condition:('a -> bool) -> values:seq<'a> -> seq<'a> * seq<'a>
Full name: Script.partition
val condition : ('a -> bool)
val values : seq<'a>
val pairs : seq<'a option * 'a option>
Multiple items
val seq : sequence:seq<'T> -> seq<'T>
Full name: Microsoft.FSharp.Core.Operators.seq
--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>
Full name: Microsoft.FSharp.Collections.seq<_>
val i : 'a
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
module Seq
from Microsoft.FSharp.Collections
val choose : chooser:('T -> 'U option) -> source:seq<'T> -> seq<'U>
Full name: Microsoft.FSharp.Collections.Seq.choose
val fst : tuple:('T1 * 'T2) -> 'T1
Full name: Microsoft.FSharp.Core.Operators.fst
val snd : tuple:('T1 * 'T2) -> 'T2
Full name: Microsoft.FSharp.Core.Operators.snd
More information