Search code examples
f#pipelinecurrying

F# Changing parameters precedence


I'm new to F# and have a question about functions pipeline. Let's say we have a function map which maps list of functions to array of values creating a list of arrays:

//val map : ('a -> 'b) list -> 'a [] -> 'b [] list     
let map funcs vals = 
    funcs |> List.map (fun f -> Array.map f vals)

Usage example:

//val it : float [] list = [[|1.0; 1.144729886|]; [|15.15426224; 23.14069263|]]
map [log; exp] [|Math.E; Math.PI|]

Is there a way to replace lambda function (fun f -> Array.map f vals) with a chain of pipeline operators?

I'd like to write smth like:

//val map : 'a [] list -> ('a -> 'b) -> 'b [] list
let map funcs vals = funcs |> List.map (vals |> Array.map)

But this doesn't work.

Many thanks,

Ivan


Solution

  • You can use this one.

    let map funcs vals = funcs |> List.map (Array.map >> ((|>) vals))
    

    The part Array.map >> ((|>) vals) partially applies f to Array.map and then composes it with the application of vals.