Module Accessor.O
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 at_least_one
=[
|
`at_least_one
]
type at_most_one
=[
|
`at_most_one
]
type coerce
=[
|
`coerce
]
type construct
=[
|
`construct
]
type get
=[
|
`get
]
type map
=[
|
`map
]
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 accessorsa
andb
. 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 afield
is afield
. - A
field
composed with avariant
is anoptional
. - A
getter
composed with avariant
is anoptional_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 useget
. However, if you compose thefield
with anoptional
,get
no longer makes sense; you must use something likeget_option
, instead.The non-operator name is
Accessor.compose
.- An
val (.@()) : 'at -> (Base.unit -> 'a -> 'b, Base.unit -> 'at -> 'bt, [> getter ]) t -> 'a
x.@(t)
extracts a single value fromx
as identified byt
. The non-operator name isAccessor.get
.
val (.@?()) : 'at -> (Base.unit -> 'a -> _, Base.unit -> 'at -> _, [> optional_getter ]) t -> 'a Base.option
x.@?(t)
extracts at most one value fromx
as identified byt
. The non-operator name isAccessor.get_option
.
val (.@*()) : 'at -> (Base.unit -> 'a -> _, Base.unit -> 'at -> _, [> many_getter ]) t -> 'a Base.list
x.@*(t)
extracts any number of values fromx
as identified byt
. The non-operator name isAccessor.to_list
.