aboutsummaryrefslogtreecommitdiff
path: root/doc/ref/general/lens.texi
blob: bdf05a61d56384d0e347094e3b048f05588ed328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@node Lenses
@section Lenses

Provided by the module @code{(hnh util lens)}

A lens system for Scheme.

@subsection Overview

@subsection Using Lenses

@defun modify container lens f
Returns a new object, with the value focused by @var{lens} replaced by
the result of calling @var{f}, with the old value, and the extra
arguments given.
@end defun

@defun set container lens value
Like modify, but sets a fixed value.
@end defun

@defun get container lens
Get the value focused by lens. Only a single value can me focused.
@end defun

@defun traversed container lens
Similar to @code{get}, but returns a list of all focused elements.

Note that this ``runs'' the lens for each elemement, (where ``modify''
doesn't). So use with caution.
@end defun

@defun lens-compose lenses ...
@defunx compose-lens lenses ...
Creates a new lens, which is the compound from all the given lenses.

Lenses composes left to right, so earlier lenses in @var{lenses} are
applied earlier.
@end defun

@subsection Built in Lenses

@deffn {Lens} car*
@deffnx {Lens} cdr*
Focuses the first or second element of a pair.
@end deffn

@deffn {Lens} ref idx
Focuses the element at index @var{idx} in a list.
@end deffn

@deffn {Lens} identity-lens
A lens focusing the given object. Showing the value returns the root
value, and setting the value just returns the new value.
@end deffn

@deffn {Lens} focus-matching predicate
A lens focusing each element of a list where @var{predicate} returns
true. This may be multiple elements.
@end deffn