@@ -1022,16 +1022,41 @@ end
1022
1022
∘ (f, g, h... ) = ∘ (f ∘ g, h... )
1023
1023
1024
1024
function show (io:: IO , c:: ComposedFunction )
1025
- show (io, c. outer)
1025
+ c . outer isa ComposedFunction ? show (io, c . outer) : _showcomposed (io, c. outer)
1026
1026
print (io, " ∘ " )
1027
- show (io, c. inner)
1027
+ _showcomposed (io, c. inner)
1028
+ end
1029
+
1030
+ # shows !f instead of (!) ∘ f when ! is the outermost function
1031
+ function show (io:: IO , c:: ComposedFunction{typeof(!)} )
1032
+ print (io, ' !' )
1033
+ _showcomposed (io, c. inner)
1034
+ end
1035
+
1036
+ _showcomposed (io:: IO , x) = show (io, x)
1037
+ # display operators like + and - inside parens
1038
+ _showcomposed (io:: IO , f:: Function ) = isoperator (Symbol (f)) ? (print (io, ' (' ); show (io, f); print (io, ' )' )) : show (io, f)
1039
+ # nesting for chained composition
1040
+ _showcomposed (io:: IO , f:: ComposedFunction ) = (print (io, ' (' ); show (io, f); print (io, ' )' ))
1041
+ # no nesting when ! is the outer function in a composition chain
1042
+ _showcomposed (io:: IO , f:: ComposedFunction{typeof(!)} ) = show (io, f)
1043
+
1044
+ function show_function (io:: IO , c:: ComposedFunction , compact:: Bool )
1045
+ if compact
1046
+ show (io, c)
1047
+ else
1048
+ print (io, " ComposedFunction(" )
1049
+ show_function (io, c. outer, false )
1050
+ print (io, " , " )
1051
+ show_function (io, c. inner, false )
1052
+ print (io, ' )' )
1053
+ end
1028
1054
end
1029
1055
1030
1056
"""
1031
1057
!f::Function
1032
1058
1033
- Predicate function negation: when the argument of `!` is a function, it returns a
1034
- function which computes the boolean negation of `f`.
1059
+ Predicate function negation: when the argument of `!` is a function, it returns a composed function which computes the boolean negation of `f`.
1035
1060
1036
1061
See also [`∘`](@ref).
1037
1062
@@ -1046,8 +1071,12 @@ julia> filter(isletter, str)
1046
1071
julia> filter(!isletter, str)
1047
1072
"∀ > 0, ∃ > 0: |-| < ⇒ |()-()| < "
1048
1073
```
1074
+
1075
+ !!! compat "Julia 1.9"
1076
+ Starting with Julia 1.9, `!f` returns a [`ComposedFunction`](@ref) instead of an anonymous function.
1049
1077
"""
1050
- ! (f:: Function ) = (x... )-> ! f (x... )
1078
+ ! (f:: Function ) = (! ) ∘ f
1079
+ ! (f:: ComposedFunction{typeof(!)} ) = f. inner # allows !!f === f
1051
1080
1052
1081
"""
1053
1082
Fix1(f, x)
0 commit comments