Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 707 Bytes

2020-07-08_a-function-returning-another-function.md

File metadata and controls

26 lines (21 loc) · 707 Bytes

A function returning another function

I was reading about Railway Oriented Programming earlier today, and ended up deciphering a lot of F# code, the following defines a function, that returns another function, the signature is:

bind : ('a -> Result<'b,'c>) -> Result<'a,'c> -> Result<'b,'c>
let bind switchFunction =
    fun twoTrackInput ->
        match twoTrackInput with
        | Success s -> switchFunction s
        | Failure f -> Failure f

You can also use the automatically curried version, with two paramaters:

let bind switchFunction twoTrackInput =
    match twoTrackInput with
    | Success s -> switchFunction s
    | Failure f -> Failure f