cnd
cnd

Reputation: 33744

Is it possible to use pipes in OCaml?

In F# I can't live without pipes (<| and |>)

let console(dashboard : Dashboard ref) = 
    let rec eat (command : string) =
        command.Split(' ','(',')') 
        |> Seq.filter(fun s -> s.Length <> 0)
        |> fun C ->
            (Seq.head C).ToUpper() |> fun head ->

Can I use <| and |> in OCaml?

Upvotes: 21

Views: 7438

Answers (1)

LiKao
LiKao

Reputation: 10658

These are available since OCaml 4.01. However, <| is named @@ there, so it has the correct operator associativity.

Alternatively, you can either define them yourself:

let (|>) v f = f v
let (<|) f v = f v  (* or: *)
let (@@) f v = f v

Or you use Ocaml batteries included, which has the |> and <| operators defined in BatStd.

Upvotes: 32

Related Questions