@@ -497,12 +497,17 @@ IndexLens(::Tuple{Properties}) = Properties()
497497# ## nice show() for optics
498498_shortstring (prev, o:: PropertyLens{field} ) where {field} = " $prev .$field "
499499_shortstring (prev, o:: IndexLens ) = " $prev [$(join (repr .(o. indices), " , " )) ]"
500- _shortstring (prev, o:: Function ) = _isoperator (o) ? " $o $prev " : " $o ($prev )"
501- _shortstring (prev, o:: Base.Fix1 ) = _isoperator (o. f) ? " $(o. x) $(o. f) $prev " : " $(o. f) ($(o. x) , $prev )"
502- _shortstring (prev, o:: Base.Fix2 ) = _isoperator (o. f) ? " $prev $(o. f) $(o. x) " : " $(o. f) ($prev , $(o. x) )"
500+ _shortstring (prev, o:: Union{ Function,Type} ) = _isoperator (o) ? " $( _fT_repr (o)) $prev " : " $( _fT_repr (o)) ($prev )"
501+ _shortstring (prev, o:: Base.Fix1 ) = _isoperator (o. f) ? " $(o. x) $(_fT_repr ( o. f)) $prev " : " $(_fT_repr ( o. f) ) ($(o. x) , $prev )"
502+ _shortstring (prev, o:: Base.Fix2 ) = _isoperator (o. f) ? " $prev $(_fT_repr ( o. f)) $(o. x) " : " $(_fT_repr ( o. f) ) ($prev , $(o. x) )"
503503_shortstring (prev, o:: Elements ) = " $prev [∗]"
504504_shortstring (prev, o:: Properties ) = " $prev [∗ₚ]"
505505
506+ # compact representation of functions and types
507+ # most notably, it deals with the module name in a consistent way: doesn't show it
508+ # by default, it's not shown for functions but shown for types, see https://github.com/JuliaLang/julia/issues/56790
509+ _fT_repr (o) = repr (o; context= :compact => true )
510+
506511# can f be stringfied using the operator (infix) syntax?
507512# otherwise uses regular function call syntax
508513_isoperator (f:: Function ) = Base. isoperator (nameof (f))
@@ -520,19 +525,23 @@ function show_optic(io, optic)
520525 outer = Iterators. dropwhile (x -> applicable (_shortstring, " " , x), opts)
521526 if ! isempty (outer)
522527 show (io, opcompose (outer... ))
528+ end
529+ if ! isempty (inner) && ! isempty (outer)
523530 print (io, " ∘ " )
524531 end
525- shortstr = reduce (inner; init= (" _" , false )) do (prev, need_parens_prev), o
526- # if _need_parens is true for this o and the one before, wrap the previous one in parentheses
527- if need_parens_prev && _need_parens (o)
528- prev = " ($prev )"
532+ if ! isempty (inner)
533+ shortstr = reduce (inner; init= (" _" , false )) do (prev, need_parens_prev), o
534+ # if _need_parens is true for this o and the one before, wrap the previous one in parentheses
535+ if need_parens_prev && _need_parens (o)
536+ prev = " ($prev )"
537+ end
538+ _shortstring (prev, o), _need_parens (o)
539+ end |> first
540+ if get (io, :compact , false )
541+ print (io, shortstr)
542+ else
543+ print (io, " (@o " , shortstr, " )" )
529544 end
530- _shortstring (prev, o), _need_parens (o)
531- end |> first
532- if get (io, :compact , false )
533- print (io, shortstr)
534- else
535- print (io, " (@o " , shortstr, " )" )
536545 end
537546end
538547
0 commit comments