Skip to content

Commit ee64566

Browse files
committed
Don't deprecate splat
Keep the splat function and mention in the documentation that it's the recommended way of constructing a Base.Splat object.
1 parent a8adb39 commit ee64566

File tree

12 files changed

+36
-25
lines changed

12 files changed

+36
-25
lines changed

base/deprecated.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ const var"@_noinline_meta" = var"@noinline"
318318

319319
# BEGIN 1.9 deprecations
320320

321-
@deprecate splat(x) Splat(x) false
322-
323321
# We'd generally like to avoid direct external access to internal fields
324322
# Core.Compiler.is_inlineable and Core.Compiler.set_inlineable! move towards this direction,
325323
# but we need to keep these around for compat

base/exports.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ export
816816
atreplinit,
817817
exit,
818818
ntuple,
819-
Splat,
819+
splat,
820820

821821
# I/O and events
822822
close,

base/iterators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ the `zip` iterator is a tuple of values of its subiterators.
346346
347347
`zip()` with no arguments yields an infinite iterator of empty tuples.
348348
349-
See also: [`enumerate`](@ref), [`Splat`](@ref Base.Splat).
349+
See also: [`enumerate`](@ref), [`Base.splat`](@ref).
350350
351351
# Examples
352352
```jldoctest

base/operators.jl

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,41 +1212,54 @@ used to implement specialized methods.
12121212
<(x) = Fix2(<, x)
12131213

12141214
"""
1215-
Splat(f)
1215+
splat(f)
12161216
12171217
Equivalent to
12181218
```julia
12191219
my_splat(f) = args->f(args...)
12201220
```
12211221
i.e. given a function returns a new function that takes one argument and splats
1222-
its argument into the original function. This is useful as an adaptor to pass
1223-
a multi-argument function in a context that expects a single argument, but
1224-
passes a tuple as that single argument. Additionally has pretty printing.
1225-
1226-
!!! compat "Julia 1.9"
1227-
This function was introduced in Julia 1.9, replacing `Base.splat(f)`.
1222+
it into the original function. This is useful as an adaptor to pass a
1223+
multi-argument function in a context that expects a single argument, but passes
1224+
a tuple as that single argument.
12281225
12291226
# Example usage:
12301227
```jldoctest
1231-
julia> map(Base.Splat(+), zip(1:3,4:6))
1228+
julia> map(splat(+), zip(1:3,4:6))
12321229
3-element Vector{Int64}:
12331230
5
12341231
7
12351232
9
12361233
1237-
julia> my_add = Base.Splat(+)
1238-
Splat(+)
1234+
julia> my_add = splat(+)
1235+
splat(+)
12391236
12401237
julia> my_add((1,2,3))
12411238
6
12421239
```
12431240
"""
1241+
splat(f) = Splat(f)
1242+
1243+
"""
1244+
Base.Splat{F} <: Function
1245+
1246+
Represents a splatted function. That is
1247+
```julia
1248+
Base.Splat(f)(args) === f(args...)
1249+
```
1250+
The preferred way to construct an instance of `Base.Splat` is to use the [`splat`](@ref) function.
1251+
1252+
!!! compat "Julia 1.9"
1253+
Splat requires at least Julia 1.9. In earlier versions `splat` returns an anonymous function instead.
1254+
1255+
See also [`splat`](@ref).
1256+
"""
12441257
struct Splat{F} <: Function
12451258
f::F
12461259
Splat(f) = new{Core.Typeof(f)}(f)
12471260
end
12481261
(s::Splat)(args) = s.f(args...)
1249-
print(io::IO, s::Splat) = print(io, "Splat(", s.f, ')')
1262+
print(io::IO, s::Splat) = print(io, "splat(", s.f, ')')
12501263
show(io::IO, s::Splat) = print(io, s)
12511264

12521265
## in and related operators

base/strings/search.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function _searchindex(s::Union{AbstractString,ByteArray},
189189
if i === nothing return 0 end
190190
ii = nextind(s, i)::Int
191191
a = Iterators.Stateful(trest)
192-
matched = all(Splat(==), zip(SubString(s, ii), a))
192+
matched = all(splat(==), zip(SubString(s, ii), a))
193193
(isempty(a) && matched) && return i
194194
i = ii
195195
end
@@ -506,7 +506,7 @@ function _rsearchindex(s::AbstractString,
506506
a = Iterators.Stateful(trest)
507507
b = Iterators.Stateful(Iterators.reverse(
508508
pairs(SubString(s, 1, ii))))
509-
matched = all(Splat(==), zip(a, (x[2] for x in b)))
509+
matched = all(splat(==), zip(a, (x[2] for x in b)))
510510
if matched && isempty(a)
511511
isempty(b) && return firstindex(s)
512512
return nextind(s, popfirst!(b)[1])::Int

doc/src/base/base.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ new
259259
Base.:(|>)
260260
Base.:(∘)
261261
Base.ComposedFunction
262-
Base.Splat
262+
Base.splat
263263
Base.Fix1
264264
Base.Fix2
265265
```

doc/src/devdocs/ast.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ These symbols appear in the `head` field of [`Expr`](@ref)s in lowered form.
425425
* `splatnew`
426426

427427
Similar to `new`, except field values are passed as a single tuple. Works similarly to
428-
`Base.Splat(new)` if `new` were a first-class function, hence the name.
428+
`splat(new)` if `new` were a first-class function, hence the name.
429429

430430
* `isdefined`
431431

stdlib/LinearAlgebra/src/LinearAlgebra.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, as
1818
vec, zero
1919
using Base: IndexLinear, promote_eltype, promote_op, promote_typeof,
2020
@propagate_inbounds, reduce, typed_hvcat, typed_vcat, require_one_based_indexing,
21-
Splat
21+
splat
2222
using Base.Broadcast: Broadcasted, broadcasted
2323
using Base.PermutedDimsArrays: CommutativeOps
2424
using OpenBLAS_jll

stdlib/LinearAlgebra/src/qr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function Base.hash(F::QRCompactWY, h::UInt)
159159
return hash(F.factors, foldr(hash, _triuppers_qr(F.T); init=hash(QRCompactWY, h)))
160160
end
161161
function Base.:(==)(A::QRCompactWY, B::QRCompactWY)
162-
return A.factors == B.factors && all(Splat(==), zip(_triuppers_qr.((A.T, B.T))...))
162+
return A.factors == B.factors && all(splat(==), zip(_triuppers_qr.((A.T, B.T))...))
163163
end
164164
function Base.isequal(A::QRCompactWY, B::QRCompactWY)
165165
return isequal(A.factors, B.factors) && all(zip(_triuppers_qr.((A.T, B.T))...)) do (a, b)

test/broadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,13 +903,13 @@ end
903903
ys = 1:2:20
904904
bc = Broadcast.instantiate(Broadcast.broadcasted(*, xs, ys))
905905
@test IndexStyle(bc) == IndexLinear()
906-
@test sum(bc) == mapreduce(Base.Splat(*), +, zip(xs, ys))
906+
@test sum(bc) == mapreduce(Base.splat(*), +, zip(xs, ys))
907907

908908
xs2 = reshape(xs, 1, :)
909909
ys2 = reshape(ys, 1, :)
910910
bc = Broadcast.instantiate(Broadcast.broadcasted(*, xs2, ys2))
911911
@test IndexStyle(bc) == IndexCartesian()
912-
@test sum(bc) == mapreduce(Base.Splat(*), +, zip(xs, ys))
912+
@test sum(bc) == mapreduce(Base.splat(*), +, zip(xs, ys))
913913

914914
xs = 1:5:3*5
915915
ys = 1:4:3*4

0 commit comments

Comments
 (0)