Search code examples
f#sequencetake

Bug ? Seq.take 10 works well , Seq.take 100 doesn't work


let a = [1;2;3;]

for i in (a |> Seq.take 10) do Console.WriteLine(i)
for i in (a |> Seq.take 100) do Console.WriteLine(i)

first line works well but second line gives error : The input sequence has an insufficient number of elements.

Yes , there is no 100 elements , they are just 3 but why 10 works then ?

Online test

after all it works on C#

using System;
using System.Linq;

class P
{ static void Main() {

 var p = new[] {1,2,3,4};

 foreach(var i in p.Take(10).ToArray()) Console.WriteLine(i);
 foreach(var i in p.Take(2).ToArray()) Console.WriteLine(i);
 foreach(var i in p.Take(100).ToArray()) Console.WriteLine(i);
}}

Online test


Solution

  • It's printing out 3 elements and then printing out the error message.