From b481860b8a9309dae1dd3e5ef18d8a67702028d0 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Fri, 5 Jan 2024 07:25:05 -0500 Subject: [PATCH] add @o alias --- src/sugar.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sugar.jl b/src/sugar.jl index 85a2436..b4178f2 100644 --- a/src/sugar.jl +++ b/src/sugar.jl @@ -1,4 +1,4 @@ -export @set, @optic, @reset, @modify, @delete, @insert, @accessor +export @set, @optic, @o, @reset, @modify, @delete, @insert, @accessor using MacroTools """ @@ -430,12 +430,17 @@ macro accessor(ex) end |> esc end -# shortcuts: +### shortcuts: +# optic macro +const var"@o" = var"@optic" + +# Elements, Properties const ∗ = Elements() const ∗ₚ = Properties() IndexLens(::Tuple{Elements}) = Elements() IndexLens(::Tuple{Properties}) = Properties() +### nice show() for optics _shortstring(prev, o::PropertyLens{field}) where {field} = "$prev.$field" _shortstring(prev, o::IndexLens) ="$prev[$(join(repr.(o.indices), ", "))]" _shortstring(prev, o::Function) = "$o($prev)"