Search code examples
f#sequences

F# take subsequence of a sequence


I need to define a function, which takes a sequence enter image description here and integers i and n as parameters and returns sub list or sub sequence of this seq, defined as followed:

enter image description here .


Solution

  • You can write:

    let subSeq i n = Seq.skip i >> Seq.take n
    

    Which is used, e.g.:

    let result = subSeq 5 10 [0..20]