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.OThe 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= constructtype 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= gettype mapper= maptype 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) ta @> bis the composition of the two accessorsaandb. 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
isomorphismcomposed with afieldis afield. - A
fieldcomposed with avariantis anoptional. - A
gettercomposed with avariantis 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 thefieldwith anoptional,getno 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 -> 'ax.@(t)extracts a single value fromxas identified byt. The non-operator name isAccessor.get.
val (.@?()) : 'at -> (Base.unit -> 'a -> _, Base.unit -> 'at -> _, [> optional_getter ]) t -> 'a Base.optionx.@?(t)extracts at most one value fromxas identified byt. The non-operator name isAccessor.get_option.
val (.@*()) : 'at -> (Base.unit -> 'a -> _, Base.unit -> 'at -> _, [> many_getter ]) t -> 'a Base.listx.@*(t)extracts any number of values fromxas identified byt. The non-operator name isAccessor.to_list.