4 people like it.

mapi with 64bit integers

A version of mapi for very long sequences that uses long integers instead of regular integers. I didn't use a mutable variable because of this http://stackoverflow.com/questions/1480582/the-mutable-variable-i-is-used-in-an-invalid-way

1: 
2: 
3: 
4: 
5: 
6: 
7: 
module Seq =
    let mapi64 f s = seq {
        let i64 = ref 0L
        for item in s do
            yield (f i64.Value item)
            i64 := !i64 + 1L
    }
module Seq

from Microsoft.FSharp.Collections
val mapi64 : f:(int64 -> 'a -> 'b) -> s:seq<'a> -> seq<'b>

Full name: Script.Seq.mapi64
val f : (int64 -> 'a -> 'b)
val s : seq<'a>
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
val i64 : int64 ref
Multiple items
val ref : value:'T -> 'T ref

Full name: Microsoft.FSharp.Core.Operators.ref

--------------------
type 'T ref = Ref<'T>

Full name: Microsoft.FSharp.Core.ref<_>
val item : 'a
property Ref.Value: int64
Raw view New version

More information

Link:http://fssnip.net/jE
Posted:3 years ago
Author:Samuel Bosch
Tags: sequences , seq , mapi , yield , int64