package kdl

  1. Overview
  2. Docs

Module Kdl.LSource

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

Sourcetype ('a, 'b) lens = {
  1. get : 'a -> 'b option;
  2. set : 'b -> 'a -> 'a option;
}
Sourceval compose : ('b, 'c) lens -> ('a, 'b) lens -> ('a, 'c) lens

Lens composition.

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

l1 |-- l2 is an infix operator for compose l2 l1.

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

Alias for (|--).

Sourceval get : 'a -> ('a, 'b) lens -> 'b option
Sourceval set : 'a -> 'b -> ('a, 'b) lens -> 'a option
Sourceval get_exn : 'a -> ('a, 'b) lens -> 'b

get_exn a l is Option.get (get a l).

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

set_exn a v l is Option.get (set a v l).

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

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

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

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

Sourceval update : ('b -> 'b option) -> 'a -> ('a, 'b) lens -> 'a option
Sourceval node_name : (node, string) lens

Lens to node.name.

Sourceval node_annot : (node, string) lens

Lens to node.annot.

Sourceval node_annot_opt : (node, string option) lens

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

Sourceval args : (node, annot_value list) lens

Lens to node.args.

Sourceval props : (node, prop list) lens

Lens to node.props.

Sourceval children : (node, node list) lens

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

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

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

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

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

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

node ?annot name is a lens to the first node with the specific name in a list. The search optionally can be narrowed by passing ?annot.

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

Same as node, but returns all possible matches instead of the first one.

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

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

Sourceval child : ?annot:string -> string -> (node, node) lens

child ?annot name is children |-- node ?annot name.

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

child_many ?annot name is children |-- node_many ?annot name.

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

child_nth n is children |-- node_nth n.

Lens to value in the annot_value pair.

Sourceval annot : (annot_value, string) lens

Lens to annot in the annot_value pair.

Sourceval annot_opt : (annot_value, string option) lens

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

Sourceval string : ([> `String of string ], string) lens

Lens to a string value.

Sourceval int : ([> `Int of int ], int) lens

Lens to an int value.

Sourceval raw_int : ([> `RawInt of string ], string) lens

Lens to a raw int value.

Sourceval float : ([> `Float of float ], float) lens

Lens to a float value.

Sourceval number : (value, [ `Float of float | `Int of int | `RawInt of string ]) lens

Lens to any numeric KDL value.

Sourceval bool : ([> `Bool of bool ], bool) lens

Lens to a boolean value.

Sourceval null : ([> `Null ], unit) lens

Lens to a null value.

Sourceval string_value : (annot_value, string) lens

string_value is value |-- string.

Sourceval int_value : (annot_value, int) lens

int_value is value |-- int.

Sourceval raw_int_value : (annot_value, string) lens

raw_int_value is value |-- raw_int.

Sourceval float_value : (annot_value, float) lens

float_value is value |-- float.

Sourceval bool_value : (annot_value, bool) lens

bool_value is value |-- bool.

Sourceval null_value : (annot_value, unit) lens

null_value is value |-- null.

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

Lens to the first element of a list.

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

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

Sourceval filter : ('a -> bool) -> ('a list, 'a list) lens
Sourceval each : ('a, 'b) lens -> ('a list, 'b list) lens

Make a lens work for multiple items. An example: top // child_many "paragraph" // each (arg 0 // value).