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 = [
| `construct
]
type equality = [
| `get
| `map
| `at_most_one
| `at_least_one
| `construct
| `coerce
]
type field = [
| `get
| `map
| `at_most_one
| `at_least_one
]
type getter = [
| `get
| `at_least_one
| `at_most_one
]
type isomorphism = [
| `get
| `map
| `at_most_one
| `at_least_one
| `construct
]
type many = [
| `get
| `map
]
type many_getter = [
| `get
]
type mapper = [
| `map
]
type nonempty = [
| `get
| `map
| `at_least_one
]
type nonempty_getter = [
| `get
| `at_least_one
]
type optional = [
| `get
| `map
| `at_most_one
]
type optional_getter = [
| `get
| `at_most_one
]
type variant = [
| `get
| `map
| `at_most_one
| `construct
]
val (@>) :
('middle, 'outer, 'kind)t->('inner, 'middle, 'kind)t->('inner, 'outer, 'kind)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.