Accessors.If
— TypeIf(modify_condition)
Restric access to locations for which modify_condition
holds.
julia> using Accessors
+(2, 4, 6)
diff --git a/dev/docstrings/index.html b/dev/docstrings/index.html
index 15f97857..e080c973 100644
--- a/dev/docstrings/index.html
+++ b/dev/docstrings/index.html
@@ -7,13 +7,13 @@
(0, 0, 0)
julia> modify(x -> 2x, obj, Elements())
-(2, 4, 6)source Restric access to locations for which Restric access to locations for which This function/type is experimental. It can be changed or deleted at any point without warning Construct a lens for accessing an element of an object at Access all properties of an object. An alias for This function/type is experimental. It can be changed or deleted at any point without warning Construct a lens for accessing an element of an object at Access all properties of an object. An alias for Based on Construct a lens for accessing a property The second constructor may not be type stable when Apply Based on Construct a lens for accessing a property The second constructor may not be type stable when Apply Delete a part according to Note that Delete a part according to Note that Extract all parts of The details of See also Extract all parts of The details of See also Insert a part according to For a callable Insert a part according to For a callable Replace a part Replace a part See also Replace a part according to For a callable See also Replace a part according to For a callable See also Replace a part of The details of See also See also Replace a part of The details of See also Compose optics Example Compose optics Example Given a simple getter function, define the corresponding Example Given a simple getter function, define the corresponding Example Define an optic and call Return a modified copy of deeply nested objects. Example Return a modified copy of deeply nested objects. Example Define an optic and call Construct an optic from an expression containing property/index access, function calls, and more. Inside the macro, The two forms, Example See also Shortcut for Example See also Shortcut for Example Return a modified copy of deeply nested objects. Example Return a modified copy of deeply nested objects. ExampleAccessors.If
— TypeIf(modify_condition)
modify_condition
holds.julia> using Accessors
+(2, 4, 6)
Accessors.If
— TypeIf(modify_condition)
modify_condition
holds.julia> using Accessors
julia> obj = (1,2,3,4,5,6);
julia> @set obj |> Elements() |> If(iseven) *= 10
-(1, 20, 3, 40, 5, 60)
Accessors.IndexLens
— MethodIndexLens(indices::Tuple)
-IndexLens(indices::Integer...)
indices
via []
.Accessors.Properties
— TypeProperties()
Properties()
is available as ∗ₚ
(\ast\_p
). This optic can also be written as @o _[∗ₚ]
.julia> using Accessors
+(1, 20, 3, 40, 5, 60)
Accessors.IndexLens
— MethodIndexLens(indices::Tuple)
+IndexLens(indices::Integer...)
indices
via []
.Accessors.Properties
— TypeProperties()
Properties()
is available as ∗ₚ
(\ast\_p
). This optic can also be written as @o _[∗ₚ]
.julia> using Accessors
julia> obj = (a=1, b=2, c=3)
(a = 1, b = 2, c = 3)
@@ -22,8 +22,8 @@
(a = "hi", b = "hi", c = "hi")
julia> modify(x -> 2x, obj, Properties())
-(a = 2, b = 4, c = 6)
mapproperties
.Accessors.PropertyLens
— MethodPropertyLens{fieldname}()
-PropertyLens(fieldname)
fieldname
of an object.fieldname
is not a constant.Accessors.Recursive
— TypeRecursive(descent_condition, optic)
optic
recursively as long as descent_condition
holds.julia> using Accessors
+(a = 2, b = 4, c = 6)
mapproperties
.Accessors.PropertyLens
— MethodPropertyLens{fieldname}()
+PropertyLens(fieldname)
fieldname
of an object.fieldname
is not a constant.Accessors.Recursive
— TypeRecursive(descent_condition, optic)
optic
recursively as long as descent_condition
holds.julia> using Accessors
julia> obj = (a=missing, b=1, c=(d=missing, e=(f=missing, g=2)))
(a = missing, b = 1, c = (d = missing, e = (f = missing, g = 2)))
@@ -35,7 +35,7 @@
(1, 2, (3, (4, 5), 6))
julia> modify(x -> 100x, obj, Recursive(x -> (x isa Tuple), Elements()))
-(100, 200, (300, (400, 500), 600))
Accessors.delete
— Functiondelete(obj, optic)
optic
of obj
.optic(delete(obj, optic))
can still have a valid value: for example, when deleting an element from a Tuple
or Vector
.julia> using Accessors
+(100, 200, (300, (400, 500), 600))
Accessors.delete
— Functiondelete(obj, optic)
optic
of obj
.optic(delete(obj, optic))
can still have a valid value: for example, when deleting an element from a Tuple
or Vector
.julia> using Accessors
julia> obj = (a=1, b=2); lens=@optic _.a;
@@ -52,7 +52,7 @@
(2,)
julia> lens(obj_d)
-2
Accessors.getall
— Functiongetall(obj, optic)
obj
that are selected by optic
. Returns a flat Tuple
of values, or an AbstractVector
if the selected parts contain arrays.getall
behavior are consireded experimental: in particular, the precise output container type might change in the future.setall
.julia> using Accessors
+2
Accessors.getall
— Functiongetall(obj, optic)
obj
that are selected by optic
. Returns a flat Tuple
of values, or an AbstractVector
if the selected parts contain arrays.getall
behavior are consireded experimental: in particular, the precise output container type might change in the future.setall
.julia> using Accessors
julia> obj = (a=1, b=(2, 3));
@@ -60,17 +60,17 @@
(1,)
julia> getall(obj, @optic _ |> Elements() |> last)
-(1, 3)
Accessors.insert
— Functioninsert(obj, optic, val)
optic
into obj
with the value val
.optic
, this law defines the insert
operation: optic(insert(obj, optic, val)) == val
(for an appropriate notion of equality).julia> using Accessors
+(1, 3)
Accessors.insert
— Functioninsert(obj, optic, val)
optic
into obj
with the value val
.optic
, this law defines the insert
operation: optic(insert(obj, optic, val)) == val
(for an appropriate notion of equality).julia> using Accessors
julia> obj = (a=1, b=2); lens=@optic _.c; val = 100;
julia> insert(obj, lens, val)
-(a = 1, b = 2, c = 100)
Accessors.modify
— Functionmodify(f, obj, optic)
x
of obj
by f(x)
. The optic
argument selects which part to replace.julia> using Accessors
+(a = 1, b = 2, c = 100)
Accessors.modify
— Functionmodify(f, obj, optic)
x
of obj
by f(x)
. The optic
argument selects which part to replace.julia> using Accessors
julia> obj = (a=1, b=2); optic=@optic _.a; f = x -> "hello $x";
julia> modify(f, obj, optic)
-(a = "hello 1", b = 2)
set
.Accessors.set
— Functionset(obj, optic, val)
optic
of obj
by val
.optic
, this law defines the set
operation: optic(set(obj, optic, val)) == val
(for an appropriate notion of equality).julia> using Accessors
+(a = "hello 1", b = 2)
set
.Accessors.set
— Functionset(obj, optic, val)
optic
of obj
by val
.optic
, this law defines the set
operation: optic(set(obj, optic, val)) == val
(for an appropriate notion of equality).julia> using Accessors
julia> obj = (a=1, b=2); lens=@optic _.a; val = 100;
@@ -80,7 +80,7 @@
julia> lens = Elements();
julia> set(obj, lens, val)
-(a = 100, b = 100)
modify
.Accessors.setall
— Functionsetall(obj, optic, values)
obj
that is selected by optic
with values
. The values
collection should have the same number of elements as selected by optic
.setall
behavior are consireded experimental: in particular, supported container types for the values
argument might change in the future.getall
, set
. The former is dual to setall
:julia> using Accessors
+(a = 100, b = 100)
modify
.Accessors.setall
— Functionsetall(obj, optic, values)
obj
that is selected by optic
with values
. The values
collection should have the same number of elements as selected by optic
.setall
behavior are consireded experimental: in particular, supported container types for the values
argument might change in the future.getall
, set
. The former is dual to setall
:julia> using Accessors
julia> obj = (a=1, b=(2, 3));
@@ -90,7 +90,7 @@
(1, 3)
julia> setall(obj, optic, (4, 5))
-(a = 4, b = (2, 5))
CompositionsBase.opcompose
— Functionoptic₁ ⨟ optic₂
optic₁
, optic₂
, ..., opticₙ
to access nested objects.julia> using Accessors
+(a = 4, b = (2, 5))
CompositionsBase.opcompose
— Functionoptic₁ ⨟ optic₂
optic₁
, optic₂
, ..., opticₙ
to access nested objects.julia> using Accessors
julia> obj = (a = (b = (c = 1,),),);
@@ -101,18 +101,18 @@
(@o _.c) ∘ (@o _.a.b)
julia> lens(obj)
-1
Accessors.@accessor
— Macro@accessor func
set
method automatically.julia> @accessor my_func(x) = x.a
+1
Accessors.@accessor
— Macro@accessor func
set
method automatically.julia> @accessor my_func(x) = x.a
julia> my_func((a=1, b=2))
1
julia> set((a=1, b=2), my_func, 100)
-(a = 100, b = 2)
Accessors.@delete
— MacroAccessors.@delete
— Macro@delete obj_optic
delete
on it.julia> using Accessors
julia> xs = (1,2,3);
julia> ys = @delete xs[2]
-(1, 3)
Accessors.@insert
— Macro@insert assignment
julia> using Accessors
+(1, 3)
Accessors.@insert
— Macro@insert assignment
julia> using Accessors
julia> t = (a=1, b=2);
@@ -120,14 +120,14 @@
(a = 1, b = 2, c = 5)
julia> t
-(a = 1, b = 2)
Accessors.@modify
— MacroAccessors.@modify
— Macro@modify(f, obj_optic)
modify
on it.julia> using Accessors
julia> xs = (1,2,3);
julia> ys = @modify(xs |> Elements() |> If(isodd)) do x
x + 1
end
-(2, 2, 4)
Accessors.@optic
— MacroAccessors.@optic
— Macro@optic expr
@o expr
_
is used as the placehold to refer to the target object.@optic
and @o
, are equivalent. We recommend using @o
for brevity unless there is a potential for confusion.julia> using Accessors
julia> struct T;a;b;end
@@ -154,7 +154,7 @@
(@o _[∗].a)
julia> modify(x -> x + 1, ((a=1,), (a=2,)), l)
-((a = 2,), (a = 3,))
@set
.Accessors.@reset
— Macro@reset assignment
obj = @set obj...
.julia> using Accessors
+((a = 2,), (a = 3,))
@set
.Accessors.@reset
— Macro@reset assignment
obj = @set obj...
.julia> using Accessors
julia> t = (a=1,)
(a = 1,)
@@ -163,7 +163,7 @@
(a = 2,)
julia> t
-(a = 2,)
Accessors.@set
— Macro@set assignment
julia> using Accessors
+(a = 2,)
Accessors.@set
— Macro@set assignment
julia> using Accessors
julia> struct T;a;b end
@@ -180,4 +180,4 @@
T(T(2, 2), 2)
julia> @set t.a.b = 3
-T(T(2, 3), 2)
Settings
This document was generated with Documenter.jl version 0.27.25 on Thursday 5 December 2024. Using Julia version 1.7.3.