Skip to content

Commit

Permalink
Add pretty printing of splat(f) as "f(...)"
Browse files Browse the repository at this point in the history
  • Loading branch information
Seelengrab committed Oct 20, 2021
1 parent 792c026 commit bdb04c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,12 @@ used to implement specialized methods.
"""
<(x) = Fix2(<, x)

struct Splat{F} <: Function
f::F
end
(s::Splat)(args) = s.f(args...)
string(s::Splat) = string("splat(", s.f, ')')

"""
splat(f)
Expand All @@ -1269,7 +1275,7 @@ julia> map(Base.splat(+), zip(1:3,4:6))
9
```
"""
splat(f) = args->f(args...)
splat(f) = Splat(f)

## in and related operators

Expand Down
5 changes: 5 additions & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ end

show(io::IO, ::MIME"text/plain", c::ComposedFunction) = show(io, c)
show(io::IO, ::MIME"text/plain", c::Returns) = show(io, c)
function show(io::IO, ::MIME"text/plain", s::Splat)
print(io, "splat(")
show(io, s.f)
print(io, ')')
end

function show(io::IO, ::MIME"text/plain", iter::Union{KeySet,ValueIterator})
isempty(iter) && get(io, :compact, false) && return show(io, iter)
Expand Down

0 comments on commit bdb04c3

Please sign in to comment.