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 d504b2c4..ec08e7b8 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)
This function/method/type is experimental. It can be changed or deleted at any point without warning
sourceAccessors.If
— TypeIf(modify_condition)
Restric access to locations for which modify_condition
holds.
julia> using Accessors
+(2, 4, 6)
Accessors.If
— TypeIf(modify_condition)
Restric access to locations for which 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)
This function/method/type is experimental. It can be changed or deleted at any point without warning
Accessors.IndexLens
— MethodIndexLens(indices::Tuple)
-IndexLens(indices::Integer...)
Construct a lens for accessing an element of an object at indices
via []
.
Accessors.Properties
— TypeProperties()
Access all properties of an object. An alias for Properties()
is available as ∗ₚ
(\ast\_p
). This optic can also be written as @optic _[∗ₚ]
.
julia> using Accessors
+(1, 20, 3, 40, 5, 60)
This function/type is experimental. It can be changed or deleted at any point without warning
Accessors.IndexLens
— MethodIndexLens(indices::Tuple)
+IndexLens(indices::Integer...)
Construct a lens for accessing an element of an object at indices
via []
.
Accessors.Properties
— TypeProperties()
Access all properties of an object. An alias for Properties()
is available as ∗ₚ
(\ast\_p
). This optic can also be written as @optic _[∗ₚ]
.
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)
Based on mapproperties
.
This function/method/type is experimental. It can be changed or deleted at any point without warning
Accessors.PropertyLens
— MethodPropertyLens{fieldname}()
-PropertyLens(fieldname)
Construct a lens for accessing a property fieldname
of an object.
The second constructor may not be type stable when fieldname
is not a constant.
Accessors.Recursive
— TypeRecursive(descent_condition, optic)
Apply optic
recursively as long as descent_condition
holds.
julia> using Accessors
+(a = 2, b = 4, c = 6)
Based on mapproperties
.
Accessors.PropertyLens
— MethodPropertyLens{fieldname}()
+PropertyLens(fieldname)
Construct a lens for accessing a property fieldname
of an object.
The second constructor may not be type stable when fieldname
is not a constant.
Accessors.Recursive
— TypeRecursive(descent_condition, optic)
Apply 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,12 +35,12 @@
(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)
Delete a part according to optic
of obj
.
julia> using Accessors
+(100, 200, (300, (400, 500), 600))
Accessors.delete
— Functiondelete(obj, optic)
Delete a part according to optic
of obj
.
julia> using Accessors
julia> obj = (a=1, b=2); lens=@optic _.a;
julia> delete(obj, lens)
-(b = 2,)
Accessors.getall
— Functiongetall(obj, optic)
Extract all parts of obj
that are selected by optic
. Returns a flat Tuple
of values, or an AbstractVector
if the selected parts contain arrays.
This function is experimental and we might change the precise output container in the future.
See also setall
.
julia> using Accessors
+(b = 2,)
Accessors.getall
— Functiongetall(obj, optic)
Extract all parts of obj
that are selected by optic
. Returns a flat Tuple
of values, or an AbstractVector
if the selected parts contain arrays.
The details of getall
behavior are consireded experimental: in particular, the precise output container type might change in the future.
See also setall
.
julia> using Accessors
julia> obj = (a=1, b=(2, 3));
@@ -48,22 +48,22 @@
(1,)
julia> getall(obj, @optic _ |> Elements() |> last)
-(1, 3)
Accessors.insert
— Functioninsert(obj, optic, val)
Insert a part according to optic
into obj
with the value val
.
julia> using Accessors
+(1, 3)
Accessors.insert
— Functioninsert(obj, optic, val)
Insert a part according to optic
into obj
with the value val
.
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)
See also set
.
Accessors.modify
— Functionmodify(f, obj, optic)
Replace a part x
of obj
by f(x)
. The optic
argument selects which part to replace.
julia> using Accessors
+(a = 1, b = 2, c = 100)
See also set
.
Accessors.modify
— Functionmodify(f, obj, optic)
Replace a part 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)
See also set
.
Accessors.set
— Functionset(obj, optic, val)
Replace a part according to optic
of obj
by val
.
julia> using Accessors
+(a = "hello 1", b = 2)
See also set
.
Accessors.set
— Functionset(obj, optic, val)
Replace a part according to optic
of obj
by val
.
julia> using Accessors
julia> obj = (a=1, b=2); lens=@optic _.a; val = 100;
julia> set(obj, lens, val)
-(a = 100, b = 2)
See also modify
.
Accessors.setall
— Functionsetall(obj, optic, values)
Replace a part of obj
that is selected by optic
with values
. The values
collection should have the same number of elements as selected by optic
.
This function is experimental and might change in the future.
See also getall
, set
. The former is dual to setall
:
julia> using Accessors
+(a = 100, b = 2)
See also modify
.
Accessors.setall
— Functionsetall(obj, optic, values)
Replace a part of obj
that is selected by optic
with values
. The values
collection should have the same number of elements as selected by optic
.
The details of setall
behavior are consireded experimental: in particular, supported container types for the values
argument might change in the future.
See also getall
, set
. The former is dual to setall
:
julia> using Accessors
julia> obj = (a=1, b=(2, 3));
@@ -73,7 +73,7 @@
(1, 3)
julia> setall(obj, optic, (4, 5))
-(a = 4, b = (2, 5))
CompositionsBase.opcompose
— Functionoptic₁ ⨟ optic₂
Compose optics optic₁
, optic₂
, ..., opticₙ
to access nested objects.
Example
julia> using Accessors
+(a = 4, b = (2, 5))
CompositionsBase.opcompose
— Functionoptic₁ ⨟ optic₂
Compose optics optic₁
, optic₂
, ..., opticₙ
to access nested objects.
Example
julia> using Accessors
julia> obj = (a = (b = (c = 1,),),);
@@ -84,18 +84,18 @@
(@optic _.c) ∘ (@optic _.a.b)
julia> lens(obj)
-1
Accessors.@accessor
— Macro@accessor func
Given a simple getter function, define the corresponding set
method automatically.
Example
julia> @accessor my_func(x) = x.a
+1
Accessors.@accessor
— Macro@accessor func
Given a simple getter function, define the corresponding set
method automatically.
Example
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
— MacroAccessors.@insert
— MacroAccessors.@insert
— MacroAccessors.@modify
— MacroAccessors.@modify
— MacroAccessors.@optic
— MacroAccessors.@optic
— Macro@optic
Construct an optic from property access and similar.
Example
julia> using Accessors
julia> struct T;a;b;end
@@ -130,7 +130,7 @@
("one", "two")
julia> set(t, (@optic _[1]), "1")
-("1", "two")
See also @set
.
Accessors.@reset
— Macro@reset assignment
Shortcut for obj = @set obj...
.
Example
julia> using Accessors
+("1", "two")
See also @set
.
Accessors.@reset
— MacroAccessors.@set
— MacroAccessors.@set
— MacroSettings
This document was generated with Documenter.jl version 0.27.25 on Saturday 6 January 2024. Using Julia version 1.7.3.