package accessor

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

To use Accessor in your own code, it is recommended to add the following to your import.ml:

module Accessor =
  (* Consider using something like [Accessor_base], [Accessor_core], or
     [Accessor_async], instead. *)
  Accessor

include Accessor.O

The O module contains a few operators and type aliases that are unlikely to clash with anything else.

type constructor = [
  1. | `construct
]
type equality = [
  1. | `get
  2. | `map
  3. | `at_most_one
  4. | `at_least_one
  5. | `construct
  6. | `coerce
]
type field = [
  1. | `get
  2. | `map
  3. | `at_most_one
  4. | `at_least_one
]
type getter = [
  1. | `get
  2. | `at_least_one
  3. | `at_most_one
]
type isomorphism = [
  1. | `get
  2. | `map
  3. | `at_most_one
  4. | `at_least_one
  5. | `construct
]
type many = [
  1. | `get
  2. | `map
]
type many_getter = [
  1. | `get
]
type mapper = [
  1. | `map
]
type nonempty = [
  1. | `get
  2. | `map
  3. | `at_least_one
]
type nonempty_getter = [
  1. | `get
  2. | `at_least_one
]
type optional = [
  1. | `get
  2. | `map
  3. | `at_most_one
]
type optional_getter = [
  1. | `get
  2. | `at_most_one
]
type variant = [
  1. | `get
  2. | `map
  3. | `at_most_one
  4. | `construct
]
val (@>) : ('middle, 'outer, 'kind) General.t -> ('inner, 'middle, 'kind) General.t -> ('inner, 'outer, 'kind) General.t

a @> b is the composition of the two accessors a and b. From left to right, a chain of composed accessors goes from outermost to innermost values. The resulting accessor kind is determined by the least powerful argument. Here are a few examples:

  • An isomorphism composed with a field is a field.
  • A field composed with a variant is an optional.
  • A getter composed with a variant is an optional_getter.

It's normally more intuitive to think of the operations you need than to think of exactly which kind of accessor you are creating. For example, if you are trying to extract a value from a data structure using a field, you would probably use get. However, if you compose the field with an optional, get no longer makes sense; you must use something like get_option, instead.

The non-operator name is Accessor.compose.

val (.@()) : 'at -> (Base.unit -> 'a -> 'b, Base.unit -> 'at -> 'bt, [> getter ]) General.t -> 'a

x.@(t) extracts a single value from x as identified by t. The non-operator name is Accessor.get.

val (.@?()) : 'at -> (Base.unit -> 'a -> _, Base.unit -> 'at -> _, [> optional_getter ]) General.t -> 'a Base.option

x.@?(t) extracts at most one value from x as identified by t. The non-operator name is Accessor.get_option.

val (.@*()) : 'at -> (Base.unit -> 'a -> _, Base.unit -> 'at -> _, [> many_getter ]) General.t -> 'a Base.list

x.@*(t) extracts any number of values from x as identified by t. The non-operator name is Accessor.to_list.

val (.@()<-) : 'at -> (_ -> _ -> 'b, Base.unit -> 'at -> 'bt, [> mapper ]) General.t -> 'b -> 'bt

x.@(t) <- y replaces any number of values in x with y, as identified by t. The non-operator name is Accessor.set.

OCaml

Innovation. Community. Security.