情况1
- 从序列中获取价值
- 打印一些值
let a = seq { yield Some 1; yield Some 2; yield Some 3; yield None }
a
|> Seq.takeWhile Option.isSome // cast 1
|> Seq.map Option.get // cast 2
|> Seq.iter (printfn "%A")
Run Code Online (Sandbox Code Playgroud)
情况二
- 一些值的过滤序列
- 打印某些值
a
|> Seq.filter Option.isSome // cast 1
|> Seq.map Option.get // cast 2
|> Seq.iter (printfn "%A")
Run Code Online (Sandbox Code Playgroud)
情况3
- 按类型按元素分组
- 打印每组的值
type AB =
| A of a : int
| B of b : string
let a = seq{
yield …
Run Code Online (Sandbox Code Playgroud)