fsprojects / Chessie

Railway-oriented programming for .NET
http://fsprojects.github.io/Chessie/
The Unlicense
188 stars 43 forks source link

Better map operator #32

Open devboy opened 8 years ago

devboy commented 8 years ago

To compose results in a nice way, more operators would be useful. The one I always end up implementing is a flipped map/(<!>):

// fromProcess returns a Result<string,ProcessMessage>

// with <!> operator
let devices' () =
    Process.exec "." Adb.adb "devices"
    |> fromProcess
    |> (<!>) Strings.toLines
    |> (<!>) (Seq.choose device)
    |> (<!>) (Seq.map ((flip>>uncurry) model))

// with flipped <!>
let inline (<**>) x y = (flip (<!>)) x y

let devices () =
    Process.exec "." Adb.adb "devices"
    |> fromProcess
    <**> Strings.toLines
    <**> (Seq.choose device)
    <**> (Seq.map ((flip>>uncurry) model))