Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Setfield.jl by Accessors.jl #41

Merged
merged 5 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ authors = ["Takafumi Arakaki <aka.tkf@gmail.com> and contributors"]
version = "0.1.4-DEV"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
InitialValues = "22cec73e-a1b8-11e9-2c92-598750a2cf9c"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
StaticNumbers = "c5e4b96a-f99f-5557-8ed2-dc63ef9b5131"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"

[compat]
InitialValues = "0.2"
Setfield = "0.5, 0.6, 0.7"
StaticNumbers = "0.3"
Tables = "1.0"
Transducers = "0.4.33"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ julia> map(modifying(a = string), data)
julia> reduce(modifying(a = +), data)
(a = 6, b = 7)

julia> using Setfield: @lens
julia> using Accessors: @optic
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing. It seems that somehow CI is using the old README.md.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a problem in updating the Manifest.toml files. I guess my setup is a bit tricky because I have Manifest.tomls checked in.


julia> data = [(a = ((b = 1,), 2),), (a = ((b = 3,), 4),)];

julia> map(modifying(@lens(_.a[1].b) => x -> 10x), data)
julia> map(modifying(@optic(_.a[1].b) => x -> 10x), data)
2-element Array{NamedTuple{(:a,),Tuple{Tuple{NamedTuple{(:b,),Tuple{Int64}},Int64}}},1}:
(a = ((b = 10,), 2),)
(a = ((b = 30,), 4),)
Expand Down
90 changes: 51 additions & 39 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# This file is machine-generated - editing it directly is not advised

[[Accessors]]
deps = ["Compat", "CompositionsBase", "ConstructionBase", "Future", "MacroTools", "Requires", "Test"]
git-tree-sha1 = "d04ec229e5edfa9dae2bb5bda761a180315f7a86"
uuid = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
version = "0.1.0"

[[ArgCheck]]
git-tree-sha1 = "59c256cf71c3982484ae4486ee86a3d7da891dea"
git-tree-sha1 = "dedbbb2ddb876f899585c4ec4433265e3017215a"
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197"
version = "2.0.0"
version = "2.1.0"

[[BangBang]]
deps = ["Compat", "ConstructionBase", "Future", "InitialValues", "LinearAlgebra", "Requires", "Setfield", "Tables", "ZygoteRules"]
git-tree-sha1 = "014e4414030507351402f4039d04fae8d1c33e21"
repo-rev = "master"
repo-url = "https://github.com/JuliaFolds/BangBang.jl.git"
git-tree-sha1 = "f42321255afc37da855b6cd9f2a1fc36c017ceee"
uuid = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
version = "0.3.30-DEV"
version = "0.3.29"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "a6a8197ae253f2c1a22b2ae17c2dfaf5812c03aa"
git-tree-sha1 = "a706ff10f1cd8dab94f59fd09c0e657db8e77ff0"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.13.0"
version = "3.23.0"

[[CompositionsBase]]
git-tree-sha1 = "f3955eb38944e5dd0fabf8ca1e267d94941d34a5"
Expand All @@ -33,15 +37,15 @@ uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.0.0"

[[DataAPI]]
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
git-tree-sha1 = "ad84f52c0b8f05aa20839484dbaf01690b41ff84"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.3.0"
version = "1.4.0"

[[DataTools]]
deps = ["InitialValues", "Setfield", "StaticNumbers", "Statistics", "Tables", "Transducers"]
path = ".."
git-tree-sha1 = "502beda0d24fb6871774d4d059a31eedff931c75"
uuid = "96c8136d-373b-4a4f-9482-8552faa6eb26"
version = "0.1.2-DEV"
version = "0.1.3"

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
Expand All @@ -67,26 +71,30 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[DocStringExtensions]]
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
git-tree-sha1 = "c5714d9bcdba66389612dc4c47ed827c64112997"
git-tree-sha1 = "50ddf44c53698f5e784bbebb3f4b21c5807401b1"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.2"
version = "0.8.3"

[[Documenter]]
deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "f3464968c65fc78846dad1c038c474a2c39bbb23"
deps = ["Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "a4875e0763112d6d017126f3944f4133abb342ae"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.25.0"
version = "0.25.5"

[[Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"

[[IOCapture]]
deps = ["Logging"]
git-tree-sha1 = "377252859f740c217b936cebcd918a44f9b53b59"
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
version = "0.1.1"

[[InitialValues]]
git-tree-sha1 = "da5d9371c7c62081d46683ee93e8f821d2c37055"
repo-rev = "master"
repo-url = "https://github.com/JuliaFolds/InitialValues.jl.git"
git-tree-sha1 = "26c8832afd63ac558b98a823265856670d898b6c"
uuid = "22cec73e-a1b8-11e9-2c92-598750a2cf9c"
version = "0.2.10-DEV"
version = "0.2.10"

[[InteractiveUtils]]
deps = ["Markdown"]
Expand All @@ -99,9 +107,9 @@ version = "1.0.0"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"
version = "0.21.1"

[[LibGit2]]
deps = ["Printf"]
Expand All @@ -119,22 +127,28 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a"
git-tree-sha1 = "6a8a2a625ab0dea913aba95c11370589e0239ff0"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.5"
version = "0.5.6"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MicroCollections]]
deps = ["BangBang", "Setfield"]
git-tree-sha1 = "e991b6a9d38091c4a0d7cd051fcb57c05f98ac03"
uuid = "128add7d-3638-4c79-886c-908ea0c25c34"
version = "0.1.0"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "10134f2ee0b1978ae7752c41306e131a684e1f06"
deps = ["Dates"]
git-tree-sha1 = "b417be52e8be24e916e34b3d70ec2da7bdf56a68"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.7"
version = "1.0.12"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
Expand All @@ -154,9 +168,9 @@ uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b"
git-tree-sha1 = "e05c53ebc86933601d36212a93b39144a2733493"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.0.1"
version = "1.1.1"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand All @@ -183,9 +197,9 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[SplittablesBase]]
deps = ["Setfield", "Test"]
git-tree-sha1 = "9a5aa2eb673771ced22bba49e8a19c1d41faab1b"
git-tree-sha1 = "ab80edcbd61a44a4dc489d06ead964a863c0a898"
uuid = "171d559e-b47b-412a-8079-5efa626c420e"
version = "0.1.9"
version = "0.1.10"

[[StaticNumbers]]
deps = ["Requires"]
Expand All @@ -205,21 +219,19 @@ version = "1.0.0"

[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "c45dcc27331febabc20d86cb3974ef095257dcf3"
git-tree-sha1 = "5131a624173d532299d1c7eb05341c18112b21b8"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.0.4"
version = "1.2.1"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[Transducers]]
deps = ["ArgCheck", "BangBang", "CompositionsBase", "DefineSingletons", "Distributed", "InitialValues", "Logging", "Markdown", "Requires", "Setfield", "SplittablesBase", "Tables"]
git-tree-sha1 = "a2281af81336e7384f4a01283608ddcdc5266631"
repo-rev = "master"
repo-url = "https://github.com/JuliaFolds/Transducers.jl.git"
deps = ["ArgCheck", "BangBang", "CompositionsBase", "DefineSingletons", "Distributed", "InitialValues", "Logging", "Markdown", "MicroCollections", "Requires", "Setfield", "SplittablesBase", "Tables"]
git-tree-sha1 = "80f9fad2026c304f391198d391a0c698b666b201"
uuid = "28d57a85-8fef-5791-bfe6-a80928e7c999"
version = "0.4.43-DEV"
version = "0.4.53"

[[UUIDs]]
deps = ["Random", "SHA"]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
DataTools = "96c8136d-373b-4a4f-9482-8552faa6eb26"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
InitialValues = "22cec73e-a1b8-11e9-2c92-598750a2cf9c"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"
2 changes: 1 addition & 1 deletion src/DataTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export averaging,

using Base: HasLength, HasShape, IteratorSize
using InitialValues: InitialValues
using Setfield: @lens, Lens, PropertyLens, modify, set
using Accessors: @optic, PropertyLens, modify, set
using StaticNumbers: static
using Statistics: Statistics, mean, std, var
using Tables: Tables
Expand Down
16 changes: 8 additions & 8 deletions src/modifying.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ x = modify(fₙ, x, lensₙ)
The binary method `g(x, y)` is equivalent to

```julia
x = set(x, lens₁, f₁(get(x, lens₁), get(y, lens₁)))
x = set(x, lens₂, f₂(get(x, lens₂), get(y, lens₂)))
x = set(x, lens₁, f₁(lens₁(x)), lens₁(y))
x = set(x, lens₂, f₂(lens₂(x)), lens₂(y))
...
x = set(x, lensₙ, fₙ(get(x, lensₙ), get(y, lensₙ)))
x = set(x, lensₙ, fₙ(lensₙ(x)), lensₙ(y))
```

Note that the locations that are not specified by the lenses keep the
Expand All @@ -41,9 +41,9 @@ julia> map(modifying(a = string), [(a = 1, b = 2), (a = 3, b = 4)])
julia> reduce(modifying(a = +), [(a = 1, b = 2), (a = 3, b = 4)])
(a = 4, b = 2)

julia> using Setfield
julia> using Accessors

julia> map(modifying(@lens(_.a[1].b) => x -> 10x),
julia> map(modifying(@optic(_.a[1].b) => x -> 10x),
[(a = ((b = 1,), 2),), (a = ((b = 3,), 4),)])
2-element Array{NamedTuple{(:a,),Tuple{Tuple{NamedTuple{(:b,),Tuple{Int64}},Int64}}},1}:
(a = ((b = 10,), 2),)
Expand All @@ -54,8 +54,8 @@ modifying

modifying(; specs...) =
ModifyingFunction(map(((k, v),) -> PropertyLens{k}() => v, Tuple(specs)))
modifying(specs::Pair{<:Lens}...) = ModifyingFunction(specs)
modifying(f, lens::Lens) = ModifyingFunction((f, lens))
modifying(specs::Pair...) = ModifyingFunction(specs)
modifying(f, lens) = ModifyingFunction((f, lens))

struct ModifyingFunction{FS} <: Function
functions::FS
Expand All @@ -72,6 +72,6 @@ end
Base.@_inline_meta
modify(z, lens) do v
Base.@_inline_meta
g(v, get(y, lens))
g(v, lens(y))
end
end
4 changes: 2 additions & 2 deletions src/oncol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ Transducers.combine(rf::OnRowFunction, a, b) =

# TODO: define better API:
Transducers._asmonoid(rf::OnRowFunction) =
OnRowFunction(map(modifying(@lens(_[2]) => Transducers._asmonoid), rf.functions))
OnRowFunction(map(modifying(@optic(_[2]) => Transducers._asmonoid), rf.functions))
Transducers.Completing(rf::OnRowFunction) =
OnRowFunction(map(modifying(@lens(_[2]) => Transducers.Completing), rf.functions))
OnRowFunction(map(modifying(@optic(_[2]) => Transducers.Completing), rf.functions))

@inline process_spec_kwargs((iname, spec)::Pair) =
process_spec(Property(iname), spec, Property(iname))
Expand Down
Loading