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?
It is a way to write your applications in the order of execution. As an exemple you could use it (I don't particularly think you should though) to avoid lets: 12 |> fun x -> e. instead of let x = 12 in e. For the Module.
Comparisons (Relational Operators) Most of these operators will look familiar: =, <>, <, <=, >, >=. OCaml distinguishes between structural equality and physical equality (essentially equality of the address of an object). = is structural equality and == is physical equality. Beware: <> is structural not-equals while !=
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With