Skip to content

Commit bdb04c3

Browse files
committed
Add pretty printing of splat(f) as "f(...)"
1 parent 792c026 commit bdb04c3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

base/operators.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,12 @@ used to implement specialized methods.
12481248
"""
12491249
<(x) = Fix2(<, x)
12501250

1251+
struct Splat{F} <: Function
1252+
f::F
1253+
end
1254+
(s::Splat)(args) = s.f(args...)
1255+
string(s::Splat) = string("splat(", s.f, ')')
1256+
12511257
"""
12521258
splat(f)
12531259
@@ -1269,7 +1275,7 @@ julia> map(Base.splat(+), zip(1:3,4:6))
12691275
9
12701276
```
12711277
"""
1272-
splat(f) = args->f(args...)
1278+
splat(f) = Splat(f)
12731279

12741280
## in and related operators
12751281

base/show.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ end
4646

4747
show(io::IO, ::MIME"text/plain", c::ComposedFunction) = show(io, c)
4848
show(io::IO, ::MIME"text/plain", c::Returns) = show(io, c)
49+
function show(io::IO, ::MIME"text/plain", s::Splat)
50+
print(io, "splat(")
51+
show(io, s.f)
52+
print(io, ')')
53+
end
4954

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

0 commit comments

Comments
 (0)