package kdl

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

Basic partial "lenses" for accessing deeply-nested KDL structures.

Note: These lenses are mostly meant to be used for getting, set is generally inefficient.

type ('s, 'a) lens = {
  1. get : 's -> 'a option;
  2. set : 'a -> 's -> 's option;
}

The partial lens. More formally, it is also known as affine traversal (the combination of lens and prism).

val compose : ('b, 'c) lens -> ('a, 'b) lens -> ('a, 'c) lens

Lens composition.

val (//) : ('a, 'b) lens -> ('b, 'c) lens -> ('a, 'c) lens

l1 // l2 is an infix operator for compose l2 l1.

val (|--) : ('a, 'b) lens -> ('b, 'c) lens -> ('a, 'c) lens

Alias for (//), the lens composition.

val get : 'a -> ('a, 'b) lens -> 'b option

Run the getter (lens.get). Results in Some value if the lens successfully matches, or None otherwise.

val set : 'a -> 'b -> ('a, 'b) lens -> 'a option

Run the setter (lens.set).

val get_exn : 'a -> ('a, 'b) lens -> 'b

get_exn a l is a raising version of get a l.

val set_exn : 'a -> 'b -> ('a, 'b) lens -> 'a

set_exn a v l is a raising version of set a v l.

val (.@()) : 'a -> ('a, 'b) lens -> 'b option

(.@()) is an indexing operator for get.

val (.@()<-) : 'a -> ('a, 'b) lens -> 'b -> 'a option

(.@()<-) is an indexing operator for set: it allows one to write document.@(lens) <- value instead of set document value lens.

val (.@!()) : 'a -> ('a, 'b) lens -> 'b

(.@!()) is an indexing operator for get_exn (raising version of (.@())).

val (.@!()<-) : 'a -> ('a, 'b) lens -> 'b -> 'a

(.@!()<-) is an indexing operator for set_exn (raising version of (.@()<-)).

val update : ('b -> 'b option) -> 'a -> ('a, 'b) lens -> 'a option

The combination of get and set.

val node_name : (node, string) lens

Lens to node.name, the node name.

val node_annot : (node, string) lens

Lens to node.annot, the optional type annotation of a node (if the annotation is not set, the partial lens fails).

val node_annot_opt : (node, string option) lens

Lens to node.annot as an option. Pass None to remove the annotation.

val args : (node, annot_value list) lens

Lens to node.args, the node arguments.

val props : (node, prop list) lens

Lens to node.props, the node properties.

val children : (node, node list) lens

Lens to node.children, i.e. all children of a node.

val arg : int -> (node, annot_value) lens

arg n is a lens to the n-th argument of a node, starting at 0. Operates in O(n) time.

val first_arg : (node, annot_value) lens

first_arg is arg 0.

val prop : string -> (node, annot_value) lens

Lens to the property with the given name. Operates in O(n) time.

val node : ?nth:int -> ?annot:string -> string -> (node list, node) lens

node ?nth ?annot name is a lens to the n-th node with the given name in a list. n is specified by the ?nth optional argument and defaults to the first node, i.e. 0. The search can optionally be narrowed by passing ?annot.

val node_many : ?annot:string -> string -> (node list, node list) lens

Same as node, but returns all possible matches.

val node_nth : int -> (node list, node) lens

Lens to the n-th node in a list, starting at 0.

val child : ?nth:int -> ?annot:string -> string -> (node, node) lens

child ?nth ?annot name is children // node ?nth ?annot name.

val child_many : ?annot:string -> string -> (node, node list) lens

child_many ?annot name is children // node_many ?annot name.

val child_nth : int -> (node, node) lens

child_nth n is children // node_nth n.

val value : (annot_value, value) lens

Lens to value in the annot_value pair.

val annot : (annot_value, string) lens

Lens to annot in the annot_value pair.

val annot_opt : (annot_value, string option) lens

Lens to annot as an option. Pass None to unset the annotation.

val string : (value, string) lens

Lens to a string value.

val number : (value, number) lens

Lens to a numeric value.

val string_number : (value, string) lens

Lens to a numeric value represented as string.

val float_number : (value, float) lens

Lens to a numeric value represented as float.

val int_number : (value, int) lens

Lens to a numeric value represented as int.

val int32_number : (value, int32) lens

Lens to a numeric value represented as int32.

val int64_number : (value, int64) lens

Lens to a numeric value represented as int64.

val nativeint_number : (value, nativeint) lens

Lens to a numeric value represented as nativeint.

val bool : (value, bool) lens

Lens to a boolean value.

val null : (value, unit) lens

Lens to a null value.

val string_value : (annot_value, string) lens

string_value is value // string.

val number_value : (annot_value, number) lens

number_value is value // number.

val string_number_value : (annot_value, string) lens

string_number_value is value // string_number.

val float_number_value : (annot_value, float) lens

float_number_value is value // float_number.

val int_number_value : (annot_value, int) lens

int_number_value is value // int_number.

val int32_number_value : (annot_value, int32) lens

int32_number_value is value // int32_number.

val int64_number_value : (annot_value, int64) lens

int64_number_value is value // int64_number.

val nativeint_number_value : (annot_value, nativeint) lens

nativeint_number_value is value // nativeint_number.

val bool_value : (annot_value, bool) lens

bool_value is value // bool.

val null_value : (annot_value, unit) lens

null_value is value // null.

val top : ('a list, 'a) lens

Lens to the first element of a list.

val nth : int -> ('a list, 'a) lens

Lens to the n-th element of a list, starting at 0.

val each : ('a, 'b) lens -> ('a list, 'b list) lens

Apply a lens to multiple items. Example: top // child_many "paragraph" // each (arg 0 // value).

val filter : ('a -> bool) -> ('a list, 'a list) lens
OCaml

Innovation. Community. Security.