diff --git a/src/optics.jl b/src/optics.jl index 18ddec7f..53a9ab37 100644 --- a/src/optics.jl +++ b/src/optics.jl @@ -210,6 +210,7 @@ end Elements Access all elements of a collection that implements `map`. +An alias for `Elements()` is available as `∗` (`\\ast`). This optic can also be written as `@optic _[∗]`. ```jldoctest julia> using Accessors @@ -295,7 +296,8 @@ end """ Properties() -Access all properties of an objects. +Access all properties of an object. +An alias for `Properties()` is available as `∗ₚ` (`\\ast\\_p`). This optic can also be written as `@optic _[∗ₚ]`. ```jldoctest julia> using Accessors diff --git a/src/sugar.jl b/src/sugar.jl index b4178f28..d755601b 100644 --- a/src/sugar.jl +++ b/src/sugar.jl @@ -1,4 +1,4 @@ -export @set, @optic, @o, @reset, @modify, @delete, @insert, @accessor +export @set, @optic, @o, @reset, @modify, @delete, @insert, @accessor, ∗, ∗ₚ using MacroTools """ diff --git a/test/test_optics.jl b/test/test_optics.jl index 5dcda4b7..e40c6be3 100644 --- a/test/test_optics.jl +++ b/test/test_optics.jl @@ -102,4 +102,10 @@ end @test Accessors.DynamicIndexLens(lastindex).([(1,2,3), (4,5)]) == [3, 5] end +@testset "shortcuts" begin + @test (@o _.a[2]) === (@optic _.a[2]) + @test (@optic _[∗]) === Elements() + @test (@optic _.a[∗][2]) === (@optic _.a |> Elements() |> _[2]) +end + end#module