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
Accessors.IfType
If(modify_condition)

Restric access to locations for which modify_condition holds.

julia> using Accessors
+(2, 4, 6)
source
Accessors.IfType
If(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/type is experimental. It can be changed or deleted at any point without warning

source
Accessors.IndexLensMethod
IndexLens(indices::Tuple)
-IndexLens(indices::Integer...)

Construct a lens for accessing an element of an object at indices via [].

source
Accessors.PropertiesType
Properties()

Access all properties of an object. An alias for Properties() is available as ∗ₚ (\ast\_p). This optic can also be written as @o _[∗ₚ].

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

source
Accessors.IndexLensMethod
IndexLens(indices::Tuple)
+IndexLens(indices::Integer...)

Construct a lens for accessing an element of an object at indices via [].

source
Accessors.PropertiesType
Properties()

Access all properties of an object. An alias for 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)

Based on mapproperties.

source
Accessors.PropertyLensMethod
PropertyLens{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.

source
Accessors.RecursiveType
Recursive(descent_condition, optic)

Apply optic recursively as long as descent_condition holds.

julia> using Accessors
+(a = 2, b = 4, c = 6)

Based on mapproperties.

source
Accessors.PropertyLensMethod
PropertyLens{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.

source
Accessors.RecursiveType
Recursive(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,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))
source
Accessors.deleteFunction
delete(obj, optic)

Delete a part according to optic of obj.

Note that 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))
source
Accessors.deleteFunction
delete(obj, optic)

Delete a part according to optic of obj.

Note that 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

See also set, insert.

source
Accessors.getallFunction
getall(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
+2

See also set, insert.

source
Accessors.getallFunction
getall(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));
 
@@ -60,17 +60,17 @@
 (1,)
 
 julia> getall(obj, @optic _ |> Elements() |> last)
-(1, 3)
source
Accessors.insertFunction
insert(obj, optic, val)

Insert a part according to optic into obj with the value val.

For a callable optic, this law defines the insert operation: optic(insert(obj, optic, val)) == val (for an appropriate notion of equality).

julia> using Accessors
+(1, 3)
source
Accessors.insertFunction
insert(obj, optic, val)

Insert a part according to optic into obj with the value val.

For a callable 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)

See also set, delete.

source
Accessors.modifyFunction
modify(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, delete.

source
Accessors.modifyFunction
modify(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.

source
Accessors.setFunction
set(obj, optic, val)

Replace a part according to optic of obj by val.

For a callable 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)

See also set.

source
Accessors.setFunction
set(obj, optic, val)

Replace a part according to optic of obj by val.

For a callable 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)

See also modify.

source
Accessors.setallFunction
setall(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
+(a = 100, b = 100)

See also modify.

source
Accessors.setallFunction
setall(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));
 
@@ -90,7 +90,7 @@
 (1, 3)
 
 julia> setall(obj, optic, (4, 5))
-(a = 4, b = (2, 5))
source
CompositionsBase.opcomposeFunction
optic₁ ⨟ optic₂

Compose optics optic₁, optic₂, ..., opticₙ to access nested objects.

Example

julia> using Accessors
+(a = 4, b = (2, 5))
source
CompositionsBase.opcomposeFunction
optic₁ ⨟ optic₂

Compose optics optic₁, optic₂, ..., opticₙ to access nested objects.

Example

julia> using Accessors
 
 julia> obj = (a = (b = (c = 1,),),);
 
@@ -101,18 +101,18 @@
 (@o _.c) ∘ (@o _.a.b)
 
 julia> lens(obj)
-1
source
Accessors.@accessorMacro
@accessor func

Given a simple getter function, define the corresponding set method automatically.

Example

julia> @accessor my_func(x) = x.a
+1
source
Accessors.@accessorMacro
@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)
source
Accessors.@deleteMacro
@delete obj_optic

Define an optic and call delete on it.

julia> using Accessors
+(a = 100, b = 2)
source
Accessors.@deleteMacro
@delete obj_optic

Define an optic and call delete on it.

julia> using Accessors
 
 julia> xs = (1,2,3);
 
 julia> ys = @delete xs[2]
-(1, 3)

Supports the same syntax as @optic. See also @set.

source
Accessors.@insertMacro
@insert assignment

Return a modified copy of deeply nested objects.

Example

julia> using Accessors
+(1, 3)

Supports the same syntax as @optic. See also @set.

source
Accessors.@insertMacro
@insert assignment

Return a modified copy of deeply nested objects.

Example

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)

Supports the same syntax as @optic. See also @set.

source
Accessors.@modifyMacro
@modify(f, obj_optic)

Define an optic and call modify on it.

julia> using Accessors
+(a = 1, b = 2)

Supports the same syntax as @optic. See also @set.

source
Accessors.@modifyMacro
@modify(f, obj_optic)

Define an optic and call 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)

Supports the same syntax as @optic. See also @set.

source
Accessors.@opticMacro
@optic expr
+(2, 2, 4)

Supports the same syntax as @optic. See also @set.

source
Accessors.@opticMacro
@optic expr
 @o expr

Construct an optic from an expression containing property/index access, function calls, and more.

Inside the macro, _ is used as the placehold to refer to the target object.

The two forms, @optic and @o, are equivalent. We recommend using @o for brevity unless there is a potential for confusion.

Example

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,))

See also @set.

source
Accessors.@resetMacro
@reset assignment

Shortcut for obj = @set obj....

Example

julia> using Accessors
+((a = 2,), (a = 3,))

See also @set.

source
Accessors.@resetMacro
@reset assignment

Shortcut for obj = @set obj....

Example

julia> using Accessors
 
 julia> t = (a=1,)
 (a = 1,)
@@ -163,7 +163,7 @@
 (a = 2,)
 
 julia> t
-(a = 2,)

Supports the same syntax as @optic. See also @set.

source
Accessors.@setMacro
@set assignment

Return a modified copy of deeply nested objects.

Example

julia> using Accessors
+(a = 2,)

Supports the same syntax as @optic. See also @set.

source
Accessors.@setMacro
@set assignment

Return a modified copy of deeply nested objects.

Example

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)

Supports the same syntax as @optic. See also @reset.

source
+T(T(2, 3), 2)

Supports the same syntax as @optic. See also @reset.

source diff --git a/dev/examples/custom_macros/index.html b/dev/examples/custom_macros/index.html index e1c9307a..c042fb2d 100644 --- a/dev/examples/custom_macros/index.html +++ b/dev/examples/custom_macros/index.html @@ -68,4 +68,4 @@ set(o, l, 100) @test o == (foo=[100,2,3], bar=:bar)
Test Passed
   Expression: o == (foo = [100, 2, 3], bar = :bar)
-   Evaluated: (foo = [100, 2, 3], bar = :bar) == (foo = [100, 2, 3], bar = :bar)

Everything works, we can do arbitrary nesting and also use += syntax etc.


This page was generated using Literate.jl.

+ Evaluated: (foo = [100, 2, 3], bar = :bar) == (foo = [100, 2, 3], bar = :bar)

Everything works, we can do arbitrary nesting and also use += syntax etc.


This page was generated using Literate.jl.

diff --git a/dev/examples/custom_optics/index.html b/dev/examples/custom_optics/index.html index 79e3b0d2..52f1ec4a 100644 --- a/dev/examples/custom_optics/index.html +++ b/dev/examples/custom_optics/index.html @@ -37,4 +37,4 @@ obj2 = @modify(lowercase, obj |> Keys()) @test obj2 == Dict("a" =>1, "b" => 2, "c" => 3)
Test Passed
   Expression: obj2 == Dict("a" => 1, "b" => 2, "c" => 3)
-   Evaluated: Dict("c" => 3, "b" => 2, "a" => 1) == Dict("c" => 3, "b" => 2, "a" => 1)

This page was generated using Literate.jl.

+ Evaluated: Dict("c" => 3, "b" => 2, "a" => 1) == Dict("c" => 3, "b" => 2, "a" => 1)

This page was generated using Literate.jl.

diff --git a/dev/examples/molecules/index.html b/dev/examples/molecules/index.html index 47292d8a..d0e4b0e5 100644 --- a/dev/examples/molecules/index.html +++ b/dev/examples/molecules/index.html @@ -42,4 +42,4 @@ ) @test res_expected == res_set
Test Passed
   Expression: res_expected == res_set
-   Evaluated: (name = "water", atoms = NamedTuple{(:name, :position), Tuple{String, NamedTuple{(:x, :y), Tuple{Float64, Int64}}}}[(name = "H", position = (x = 4.0, y = 1)), (name = "O", position = (x = 4.0, y = 0)), (name = "H", position = (x = 4.0, y = 0))]) == (name = "water", atoms = NamedTuple{(:name, :position), Tuple{String, NamedTuple{(:x, :y), Tuple{Float64, Int64}}}}[(name = "H", position = (x = 4.0, y = 1)), (name = "O", position = (x = 4.0, y = 0)), (name = "H", position = (x = 4.0, y = 0))])

This page was generated using Literate.jl.

+ Evaluated: (name = "water", atoms = NamedTuple{(:name, :position), Tuple{String, NamedTuple{(:x, :y), Tuple{Float64, Int64}}}}[(name = "H", position = (x = 4.0, y = 1)), (name = "O", position = (x = 4.0, y = 0)), (name = "H", position = (x = 4.0, y = 0))]) == (name = "water", atoms = NamedTuple{(:name, :position), Tuple{String, NamedTuple{(:x, :y), Tuple{Float64, Int64}}}}[(name = "H", position = (x = 4.0, y = 1)), (name = "O", position = (x = 4.0, y = 0)), (name = "H", position = (x = 4.0, y = 0))])

This page was generated using Literate.jl.

diff --git a/dev/examples/specter/index.html b/dev/examples/specter/index.html index 3a8d559d..e400bdc8 100644 --- a/dev/examples/specter/index.html +++ b/dev/examples/specter/index.html @@ -54,4 +54,4 @@ out = optic(data) @test out == [1,2,3]
Test Passed
   Expression: out == [1, 2, 3]
-   Evaluated: Union{Missing, Int64}[1, 2, 3] == [1, 2, 3]

This page was generated using Literate.jl.

+ Evaluated: Union{Missing, Int64}[1, 2, 3] == [1, 2, 3]

This page was generated using Literate.jl.

diff --git a/dev/getting_started/index.html b/dev/getting_started/index.html index 678729df..f6a2a32f 100644 --- a/dev/getting_started/index.html +++ b/dev/getting_started/index.html @@ -44,4 +44,4 @@ (a = (b = (1, 20),), c = 3) julia> @set splitext("some_file.py")[2] = ".jl" -"some_file.jl" +"some_file.jl" diff --git a/dev/index.html b/dev/index.html index f5e796f5..c1bdfc4c 100644 --- a/dev/index.html +++ b/dev/index.html @@ -13,4 +13,4 @@ (a = 1, b = 4) julia> nt -(a = 1, b = 4)

For more detail, see this tutorial and/or watch this video:

JuliaCon2020 Changing the immutable

Featured extensions

+(a = 1, b = 4)

For more detail, see this tutorial and/or watch this video:

JuliaCon2020 Changing the immutable

Featured extensions

diff --git a/dev/internals/index.html b/dev/internals/index.html index d62c851e..5fdd91fa 100644 --- a/dev/internals/index.html +++ b/dev/internals/index.html @@ -4,17 +4,17 @@ end macro myinsert(ex) insertmacro(mytransform, ex) -end

See also opticmacro, setmacro.

source
Accessors.mappropertiesMethod
mapproperties(f, obj)

Construct a copy of obj, with each property replaced by the result of applying f to it.

julia> using Accessors
+end

See also opticmacro, setmacro.

source
Accessors.mappropertiesMethod
mapproperties(f, obj)

Construct a copy of obj, with each property replaced by the result of applying f to it.

julia> using Accessors
 
 julia> obj = (a=1, b=2);
 
 julia> Accessors.mapproperties(x -> x+1, obj)
-(a = 2, b = 3)

Implementation

This function should not be overloaded directly. Instead both of

  • ConstructionBase.getproperties
  • ConstructionBase.setproperties

should be overloaded. This function/type is experimental. It can be changed or deleted at any point without warning

source
Accessors.opticcomposeMethod
opticcompose([optic₁, [optic₂, [optic₃, ...]]])

Compose optic₁, optic₂ etc. There is one subtle point here: While the two composition orders (optic₁ ⨟ optic₂) ⨟ optic₃ and optic₁ ⨟ (optic₂ ⨟ optic₃) have equivalent semantics, their performance may not be the same.

The opticcompose function tries to use a composition order, that the compiler likes. The composition order is therefore not part of the stable API.

source
Accessors.opticmacroMethod
opticmacro(optictransform, ex::Expr)

This function can be used to create a customized variant of @optic. It works by applying optictransform to the created optic at runtime.

# new_optic = mytransform(optic)
+(a = 2, b = 3)

Implementation

This function should not be overloaded directly. Instead both of

  • ConstructionBase.getproperties
  • ConstructionBase.setproperties

should be overloaded. This function/type is experimental. It can be changed or deleted at any point without warning

source
Accessors.opticcomposeMethod
opticcompose([optic₁, [optic₂, [optic₃, ...]]])

Compose optic₁, optic₂ etc. There is one subtle point here: While the two composition orders (optic₁ ⨟ optic₂) ⨟ optic₃ and optic₁ ⨟ (optic₂ ⨟ optic₃) have equivalent semantics, their performance may not be the same.

The opticcompose function tries to use a composition order, that the compiler likes. The composition order is therefore not part of the stable API.

source
Accessors.opticmacroMethod
opticmacro(optictransform, ex::Expr)

This function can be used to create a customized variant of @optic. It works by applying optictransform to the created optic at runtime.

# new_optic = mytransform(optic)
 macro myoptic(ex)
     opticmacro(mytransform, ex)
-end

See also setmacro.

source
Accessors.setmacroMethod
setmacro(optictransform, ex::Expr; overwrite::Bool=false)

This function can be used to create a customized variant of @set. It works by applying optictransform to the optic that is used in the customized @set macro at runtime.

Example

function mytransform(optic::Lens)::Lens
+end

See also setmacro.

source
Accessors.setmacroMethod
setmacro(optictransform, ex::Expr; overwrite::Bool=false)

This function can be used to create a customized variant of @set. It works by applying optictransform to the optic that is used in the customized @set macro at runtime.

Example

function mytransform(optic::Lens)::Lens
     ...
 end
 macro myset(ex)
     setmacro(mytransform, ex)
-end

See also opticmacro.

source
+end

See also opticmacro.

source diff --git a/dev/lenses/index.html b/dev/lenses/index.html index fdab3e79..8a71cdad 100644 --- a/dev/lenses/index.html +++ b/dev/lenses/index.html @@ -38,4 +38,4 @@ @assert set(obj, lens, lens(obj)) ≅ obj # Setting what was already there changes nothing. @assert set(set(obj, lens, val1), lens, val2) ≅ set(obj, lens, val2) - # The last set wins.

Here is an appropriate notion of equality or an approximation of it. In most contexts this is simply ==. But in some contexts it might be ===, , isequal or something else instead. For instance == does not work in Float64 context, because get(set(obj, lens, NaN), lens) == NaN can never hold. Instead isequal or ≅(x::Float64, y::Float64) = isequal(x,y) | x ≈ y are possible alternatives.

See also @optic, set, modify.

+ # The last set wins.

Here is an appropriate notion of equality or an approximation of it. In most contexts this is simply ==. But in some contexts it might be ===, , isequal or something else instead. For instance == does not work in Float64 context, because get(set(obj, lens, NaN), lens) == NaN can never hold. Instead isequal or ≅(x::Float64, y::Float64) = isequal(x,y) | x ≈ y are possible alternatives.

See also @optic, set, modify.

diff --git a/dev/search/index.html b/dev/search/index.html index ca2f4932..8e447747 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -1,2 +1,2 @@ -Search · Accessors.jl

Loading search...

    +Search · Accessors.jl

    Loading search...