Today I Learned

hashrocket A Hashrocket project

Single arg pattern matching with the fun operator

Reasonml has pattern matching in specific syntaxes and one of those syntaxes is the fun operator which helps you define multiple patterns for single argument functions.

let something = 
  fun
  | "hello" => "world"
  | "busta" => "rhymes"
  | x => "something else"
Reason

when called:

something("hello")
/* results in "world" */
Reason

This doesn't work for multiple arguments however, so when you see something like this:

let add =
  fun
  | (1, 1) => 3
  | (x, y) => x + y;
Reason

just remember that the single argument in this case is a tuple, called like this add((1, 3)).

See More #reasonml TILs