
Untitled
By: a guest on
Oct 14th, 2010 | syntax:
OCaml | size: 0.66 KB | hits: 1,203 | expires: Never
module Ops2 =
let inline (|!>) a b = b !a
let inline (<==) a b = a := b !a
let inline (|?>) a b = match a with Some x -> Some(b x) | _ -> None
let inline (|?) a b = match a with Some x -> x | _ -> b()
(* Delayed (C# style) null coalescing for Option types *)
None |? fun()-> 1
(* Option piping, same as |> put for option types *)
Some 1 |?> (fun x -> x + 1)
None |?> (fun x -> x + 1)
(* ref update operator, applies the right operand to the left
and stores the result in the left operand *)
let x = ref 1
x <== (fun x -> x + 1)
printfn "%A" x
(* ref piping, same as |> but for refs *)
x |!> (fun x -> x + 1)