怎么采取不超过常数?

mou*_*ick 3 f#

我想学习F#.

我想不再使用Seq(或数组)中的元素而不是常量.

我用这个代码:[ "11"; "12"; "13" ] |> Seq.take 2 |> Seq.toList |> Seq.iter (printf "%A ")我明白了"11" "12"

如果我尝试[ "11"; "12"; "13" ] |> Seq.take 4 |> Seq.toList |> Seq.iter (printf "%A ")我会得到一个例外System.InvalidOperationException: The input sequence has an insufficient number of elements.

我可以把它视为同时[ "11"; "12"; "13" ] |> Seq.takeWhile (fun elem -> true) |> Seq.toList |> Seq.iter (printf "%A ") 但我不知道如何停止接受一些不变的限制.

所以我需要类似的东西[ "11"; "12"; "13" ] |> Seq.takeNoMoreThan 4 |> Seq.toList |> Seq.iter (printf "%A ").

我不知道如何实现我的目标.

pad*_*pad 7

您应该使用Seq.truncate.