20 people like it.

ZipMap

Helper function to fold an operator over two sequences so {x1; x2; x3; x4; ...} and {y1; y2; y3; y4; ..} is mapped with an operator f to {f x1 y1; f x2 y2; ...} See example

1: 
2: 
3: 
let inline ZipMap f a b = Seq.zip a b |> Seq.map (fun (x,y) -> f x y)
let inline mult a b = ZipMap (*) a b
mult [1;2;3] [4;5;6]
val ZipMap : f:('a -> 'b -> 'c) -> a:seq<'a> -> b:seq<'b> -> seq<'c>

Full name: Script.ZipMap
val f : ('a -> 'b -> 'c)
val a : seq<'a>
val b : seq<'b>
module Seq

from Microsoft.FSharp.Collections
val zip : source1:seq<'T1> -> source2:seq<'T2> -> seq<'T1 * 'T2>

Full name: Microsoft.FSharp.Collections.Seq.zip
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val x : 'a
val y : 'b
val mult : a:seq<'a> -> b:seq<'b> -> seq<'c> (requires member ( * ))

Full name: Script.mult
val a : seq<'a> (requires member ( * ))
val b : seq<'b> (requires member ( * ))
Raw view Test code New version

More information

Link:http://fssnip.net/3o
Posted:13 years ago
Author:Carsten König
Tags: composition