序列簡介

序列是可以列舉的一系列元素。它是 System.Collections.Generic.IEnumerable 和 lazy 的別名。它儲存了一系列相同型別的元素(可以是任何值或物件,甚至是另一個序列)。Seq.module 中的函式可用於對其進行操作。

以下是序列列舉的簡單示例:

let mySeq = { 0..20 } // Create a sequence of int from 0 to 20
mySeq
|> Seq.iter (printf "%i ") // Enumerate each element of the sequence and print it

輸出:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20