Hi!

You could rewrite the function like this:

1
2
3
4
5
6
7
8
9
10
11
12
 

let data = [|1;2;3;4;5|]

let map_by_pair arr f =
   arr
   |> Seq.pairwise
   |> Seq.map (fun (a,b) -> f a b)
   |> Seq.toArray
   
printfn "%A" (map_by_pair data (*))

However, I think there is nothing wrong with your original code. It might very well be faster.

Of course, you might also just use Seq.pairwise directly if it matches the situation.

By on 5/20/2011 10:43 AM ()

Yes, the [b]Seq.pairwise[/b] is the key to.

Thank you a lot and best wishes!

By on 5/20/2011 10:30 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper