package ordering

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
val let= : t -> (unit -> t) -> t

A convenient operator for efficiently chaining multiple comparisons together. For example, you can write

          let compare { x; y; z } t =
            let open Ordering.O in
            let= () = compare_x x t.x in
            let= () = compare_y y t.y in
            compare_z z t.z

or, a bit less compactly but more symmetrically

          let compare { x; y; z } t =
            let open Ordering.O in
            let= () = compare_x x t.x in
            let= () = compare_y y t.y in
            let= () = compare_z z t.z in
            Eq

to chain three comparisons instead of the usual triply nested match.

Note that the resulting code can be up to 2x slower than nested matching due to extra allocations that we are unable to eliminate (as of Nov 2021), so you should use let= only where appropriate.

OCaml

Innovation. Community. Security.