Skip to content

Commit

Permalink
add @o alias
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Jan 5, 2024
1 parent 816c8bc commit b481860
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/sugar.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export @set, @optic, @reset, @modify, @delete, @insert, @accessor
export @set, @optic, @o, @reset, @modify, @delete, @insert, @accessor
using MacroTools

"""
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit b481860

Please sign in to comment.