Nick
Nick

Reputation: 9051

How to take the number field from a sequence of BigInteger in F#?

Take this factorial sequence as an example:

factTake 5;;
val it : seq<System.Numerics.BigInteger> =
  seq [1 {IsEven = false;
          IsOne = true;
          IsPowerOfTwo = true;
          IsZero = false;
          Sign = 1;}; 2 {IsEven = true;
                         IsOne = false;
                         IsPowerOfTwo = true;
                         IsZero = false;
                         Sign = 1;}; 6 {IsEven = true;
                                        IsOne = false;
                                        IsPowerOfTwo = false;
                                        IsZero = false;
                                        Sign = 1;}; 24 {IsEven = true;
                                                        IsOne = false;
                                                        IsPowerOfTwo = false;
                                                        IsZero = false;
                                                        Sign = 1;}; ...]

How can I collect the numbers in the result into a list, like this:

[1; 2; 6; 24]

Update

Thanks for @Nicole A and @RCH's comment. The problem turns out to be simple:

factTake 8 |> Seq.toList |> printfn "%A"

[1; 2; 6; 24; 120; 720; 5040; 40320]
val it : unit = ()

This post on printfn from F# for fun and profit is also useful: Formatted text using printf!

Upvotes: 0

Views: 132

Answers (1)

CaringDev
CaringDev

Reputation: 8551

As we found out collectively:

factTake 8 |> Seq.toList |> printfn "%A"

Upvotes: 2

Related Questions