我需要获取F#列表中某个元素第一次出现后的子集。我使用了一个简单的递归程序来实现:
这对我的需求来说有效,但我想知道是否有更好的方法使用F#语言中现有的List函数来完成此操作。
// Returns a subset of a list from the first occurrence of a given item
// e.g. ignoreUpTo "B" ["A";"B";"C";"D"] yields ["C"; "D"]
let rec ignoreUpTo item l =
match l with
| hd::tl -> if hd = item then tl else ignoreUpTo item tl
| _ -> []
这对我的需求来说有效,但我想知道是否有更好的方法使用F#语言中现有的List函数来完成此操作。