Skip to content

!foo should use (!) ∘ foo #44748

Closed
@stevengj

Description

As discussed on Discourse, it would be nice to have !foo return a ComposedFunction, which would

  1. allow dispatch and specialized methods for !foo
  2. allow nicer pretty printing of !foo as "!foo" rather than as "#xx (generic function with 1 method)" (by overloading show for ComposedFunction{typeof(!)})
  3. allow !!foo === foo

Although !foo and f ∘ g were introduced at the same time in #17155, when was subsequently updated in Julia 1.6 to return a special ComposedFunction type (#37517), the ! implementation was not correspondingly updated, which seems like an oversight.

On a related note, it would also be good to fix the ComposedFunction show method to put parentheses around operators (or other composed functions), as this is currently broken:

julia> (!)  isnan
!  isnan

julia> !  isnan
ERROR: syntax: "" is not a unary operator
Stacktrace:
 [1] top-level scope
   @ none:1

Should be a fairly easy PR.

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsgood first issueIndicates a good issue for first-time contributors to Julia

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions