package reason-standard

  1. Overview
  2. Docs

Module Option.Infix

Operators for code that works extensively with Options.

This module is intended to be opened at the top of a block of code (or module) that uses its operators extensively.

  let nameToAge = Map.String.ofArray [|
    ("Ant", 1);
    ("Bat", 5);
  |] in          

  Option.Infix.(
    Map.get nameToAge "Ant" >>= (fun antAge -> 
      Map.get nameToAge "Bat" >>| (fun batAge -> 
        Int.absolute(batAge - antAge)
      )
    )
  )
  (* Some (4) *)
val (>>|) : 'a option -> ('a -> 'b) -> 'b option

The operator version of map

Examples

Option.Infix.(Some "desserts" >>| String.reverse) = Some "stressed"
Option.Infix.(None >>| String.reverse) = None
val (>>=) : 'a option -> ('a -> 'b option) -> 'b option

The operator version of flatMap

Examples

Option.Infix.(Some [1, 2, 3] >>= List.head) = Some 1
Option.Infix.(Some [] >>= List.head) = None
OCaml

Innovation. Community. Security.