Skip to content

Commit 15bb131

Browse files
committed
show types within optics same as functions
For example, show result for @o Tuple(_.a[2]): before: "Tuple ∘ (@o _.a[2])" with this PR: "(@o Tuple(_.a[2]))"
1 parent 11e9dc4 commit 15bb131

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/sugar.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ IndexLens(::Tuple{Properties}) = Properties()
493493
### nice show() for optics
494494
_shortstring(prev, o::PropertyLens{field}) where {field} = "$prev.$field"
495495
_shortstring(prev, o::IndexLens) ="$prev[$(join(repr.(o.indices), ", "))]"
496-
_shortstring(prev, o::Function) = _isoperator(o) ? "$o$prev" : "$o($prev)"
496+
_shortstring(prev, o::Union{Function,Type}) = _isoperator(o) ? "$o$prev" : "$o($prev)"
497497
_shortstring(prev, o::Base.Fix1) = _isoperator(o.f) ? "$(o.x) $(o.f) $prev" : "$(o.f)($(o.x), $prev)"
498498
_shortstring(prev, o::Base.Fix2) = _isoperator(o.f) ? "$prev $(o.f) $(o.x)" : "$(o.f)($prev, $(o.x))"
499499
_shortstring(prev, o::Elements) = "$prev[∗]"

test/test_core.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ end
465465
@test sprint(show, (@optic (_.a + 1) * 2)) == "(@o (_.a + 1) * 2)"
466466
@test sprint(show, (@optic (_.a * 2) + 1)) == "(@o (_.a * 2) + 1)"
467467
@test sprint(show, (@optic log(_.a[2]))) == "(@o log(_.a[2]))"
468+
@test sprint(show, (@optic Tuple(_.a[2]))) == "(@o Tuple(_.a[2]))"
468469
@test sprint(show, (@optic log(_).a[2])) == "(@o _.a[2]) ∘ log" # could be shorter, but difficult to dispatch correctly without piracy
469470
@test sprint(show, (@optic log(_.a[2])); context=:compact => true) == "log(_.a[2])"
470471
end

0 commit comments

Comments
 (0)