Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate |> #24886

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,8 @@ end

@deprecate merge!(repo::LibGit2.GitRepo, args...; kwargs...) LibGit2.merge!(repo, args...; kwargs...)

@deprecate |>(x, f) f(x)

# issue #24019
@deprecate similar(a::Associative) empty(a)
@deprecate similar(a::Associative, ::Type{Pair{K,V}}) where {K, V} empty(a, K, V)
Expand Down
4 changes: 2 additions & 2 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,11 @@ Low-level macro used to mark expressions returned by a macro that should be docu
more than one expression is marked then the same docstring is applied to each expression.

macro example(f)
quote
esc(quote
\$(f)() = 0
@__doc__ \$(f)(x) = 1
\$(f)(x, y) = 2
end |> esc
end)
end

`@__doc__` has no effect when a macro that uses it is not documented.
Expand Down
6 changes: 3 additions & 3 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ end

function fuzzysort(search, candidates)
scores = map(cand -> (fuzzyscore(search, cand), -levenshtein(search, cand)), candidates)
candidates[sortperm(scores)] |> reverse
reverse(candidates[sortperm(scores)])
end

# Levenshtein Distance
Expand Down Expand Up @@ -362,9 +362,9 @@ moduleusings(mod) = ccall(:jl_module_usings, Any, (Any,), mod)
filtervalid(names) = filter(x->!ismatch(r"#", x), map(string, names))

accessible(mod::Module) =
[filter!(s->Base.isdeprecated(mod, s), names(mod, true, true));
filtervalid(unique([filter!(s->Base.isdeprecated(mod, s), names(mod, true, true));
map(names, moduleusings(mod))...;
builtins] |> unique |> filtervalid
builtins]))

completions(name) = fuzzysort(name, accessible(Main))
completions(name::Symbol) = completions(string(name))
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ export
\,
^,
|,
|>,
~,
:,
=>,
Expand Down
5 changes: 2 additions & 3 deletions base/markdown/GitHub/GitHub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function fencedcode(stream::IO, block::MD)
if startswith(stream, string(ch) ^ n)
if !startswith(stream, string(ch))
if flavor == "math"
push!(block, LaTeX(String(take!(buffer)) |> chomp))
push!(block, LaTeX(chomp(String(take!(buffer)))))
else
push!(block, Code(flavor, String(take!(buffer)) |> chomp))
push!(block, Code(flavor, chomp(String(take!(buffer)))))
end
return true
else
Expand Down Expand Up @@ -63,4 +63,3 @@ end

linebreak, escapes, en_dash, inline_code, asterisk_bold,
asterisk_italic, image, footnote_link, link, autolink]

4 changes: 2 additions & 2 deletions base/markdown/render/terminal/formatting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
# Wrapping

function ansi_length(s)
replace(s, r"\e\[[0-9]+m", "") |> length
length(replace(s, r"\e\[[0-9]+m", ""))
end

words(s) = split(s, " ")
Expand All @@ -64,7 +64,7 @@ function wrapped_lines(s::AbstractString; width = 80, i = 0)
end
ws = words(s)
lines = AbstractString[ws[1]]
i += ws[1] |> ansi_length
i += ansi_length(ws[1])
for word in ws[2:end]
word_length = ansi_length(word)
if i + word_length + 1 > width
Expand Down
15 changes: 0 additions & 15 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -917,21 +917,6 @@ julia> widen(1.5f0)
"""
widen(x::T) where {T<:Number} = convert(widen(T), x)

# function pipelining

"""
|>(x, f)

Applies a function to the preceding argument. This allows for easy function chaining.

# Examples
```jldoctest
julia> [1:5;] |> x->x.^2 |> sum |> inv
0.01818181818181818
```
"""
|>(x, f) = f(x)

# function composition

"""
Expand Down
1 change: 0 additions & 1 deletion doc/src/manual/mathematical-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ Julia applies the following order and associativity of operations, from highest
| Bitshifts | `<< >> >>>` | Left |
| Addition | `+ - \| ⊻` | Left[^2] |
| Syntax | `: ..` | Left |
| Syntax | `\|>` | Left |
| Syntax | `<\|` | Right |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If |> is being removed, shouldn't <| also be removed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Not sure. Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Yeah dunno.

| Comparisons | `> < >= <= == === != !== <:` | Non-associative |
| Control flow | `&&` followed by `\|\|` followed by `?` | Right |
Expand Down
1 change: 0 additions & 1 deletion doc/src/stdlib/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ Core.applicable
Core.invoke
Base.invokelatest
new
Base.:(|>)
Base.:(∘)
Base.equalto
```
Expand Down
2 changes: 1 addition & 1 deletion stdlib/IterativeEigenSolvers/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ end

@testset "promotion" begin
eigs(rand(1:10, 10, 10))
eigs(rand(1:10, 10, 10), rand(1:10, 10, 10) |> t -> t't)
eigs(rand(1:10, 10, 10), (t -> t't)(rand(1:10, 10, 10)))
svds(rand(1:10, 10, 8))
@test_throws MethodError eigs(big.(rand(1:10, 10, 10)))
@test_throws MethodError eigs(big.(rand(1:10, 10, 10)), rand(1:10, 10, 10))
Expand Down
6 changes: 3 additions & 3 deletions stdlib/SuiteSparse/test/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ end
@test logdet(ldltfact(A1pd)) ≈ logdet(Array(A1pd))
@test isposdef(A1pd)
@test !isposdef(A1)
@test !isposdef(A1 + A1' |> t -> t - 2eigmax(Array(t))*I)
@test !isposdef((t -> t - 2eigmax(Array(t))*I)(A1 + A1'))

if elty <: Real
@test CHOLMOD.issymmetric(Sparse(A1pd, 0))
Expand Down Expand Up @@ -634,7 +634,7 @@ end
end

@testset "Issue 14134" begin
A = CHOLMOD.Sparse(sprandn(10,5,0.1) + I |> t -> t't)
A = CHOLMOD.Sparse((t -> t't)(sprandn(10,5,0.1) + I))
b = IOBuffer()
serialize(b, A)
seekstart(b)
Expand Down Expand Up @@ -677,7 +677,7 @@ end
end

@testset "Real factorization and complex rhs" begin
A = sprandn(5, 5, 0.4) |> t -> t't + I
A = (t -> t't + I)(sprandn(5, 5, 0.4))
B = complex.(randn(5, 2), randn(5, 2))
@test cholfact(A)\B ≈ A\B
end
Expand Down
1 change: 0 additions & 1 deletion test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ import Base.Meta: isexpr

# PR #17623: Fused binary operators
@test [true] .* [true] == [true]
@test [1,2,3] .|> (x->x+1) == [2,3,4]
let g = Int[], ⊕ = (a,b) -> let c=a+2b; push!(g, c); c; end
@test [1,2,3] .⊕ [10,11,12] .⊕ [100,200,300] == [221,424,627]
@test g == [21,221,24,424,27,627] # test for loop fusion
Expand Down
8 changes: 4 additions & 4 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ module MacroGenerated
import Base.@__doc__

macro example_1(f)
quote
esc(quote
$(f)() = 0
@__doc__ $(f)(x) = x
$(f)(x, y) = x + y
end |> esc
end)
end

"f"
Expand All @@ -397,11 +397,11 @@ end
@example_1 _f

macro example_2(f)
quote
esc(quote
$(f)() = 0
@__doc__ $(f)(x) = x
@__doc__ $(f)(x, y) = x + y
end |> esc
end)
end

"g"
Expand Down
2 changes: 1 addition & 1 deletion test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ mktempdir() do dir
@test isdir(joinpath(cache_repo, ".git"))
# set a remote branch
branch = "upstream"
LibGit2.GitRemote(repo, branch, repo_url) |> close
close(LibGit2.GitRemote(repo, branch, repo_url))

# test remote's representation in the repo's config
config = joinpath(cache_repo, ".git", "config")
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ using Test
@test ones(0,0)*ones(0,4) == zeros(0,4)
@test ones(3,0)*ones(0,0) == zeros(3,0)
@test ones(0,0)*ones(0,0) == zeros(0,0)
@test Matrix{Float64}(uninitialized, 5, 0) |> t -> t't == zeros(0,0)
@test Matrix{Float64}(uninitialized, 5, 0) |> t -> t*t' == zeros(5,5)
@test Matrix{Complex128}(uninitialized, 5, 0) |> t -> t't == zeros(0,0)
@test Matrix{Complex128}(uninitialized, 5, 0) |> t -> t*t' == zeros(5,5)
@test (t -> t't)(Matrix{Float64}(uninitialized, 5, 0)) == zeros(0,0)
@test (t -> t*t')(Matrix{Float64}(uninitialized, 5, 0)) == zeros(5,5)
@test (t -> t't)(Matrix{Complex128}(uninitialized, 5, 0)) == zeros(0,0)
@test (t -> t*t')(Matrix{Complex128}(uninitialized, 5, 0)) == zeros(5,5)
end
@testset "2x2 matmul" begin
AA = [1 2; 3 4]
Expand Down
16 changes: 8 additions & 8 deletions test/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ srand(123)

debug && println("Test basic type functionality")
@test_throws DimensionMismatch LowerTriangular(randn(5, 4))
@test LowerTriangular(randn(3, 3)) |> t -> [size(t, i) for i = 1:3] == [size(Matrix(t), i) for i = 1:3]
@test (t -> [size(t, i) for i = 1:3] == [size(Matrix(t), i) for i = 1:3])(LowerTriangular(randn(3, 3)))

# The following test block tries to call all methods in base/linalg/triangular.jl in order for a combination of input element types. Keep the ordering when adding code.
for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloat}, Int)
Expand All @@ -22,7 +22,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
(UnitLowerTriangular, :L))

# Construct test matrix
A1 = t1(elty1 == Int ? rand(1:7, n, n) : convert(Matrix{elty1}, (elty1 <: Complex ? complex.(randn(n, n), randn(n, n)) : randn(n, n)) |> t -> chol(t't) |> t -> uplo1 == :U ? t : adjoint(t)))
A1 = t1(elty1 == Int ? rand(1:7, n, n) : convert(Matrix{elty1}, (t -> uplo1 == :U ? t : adjoint(t))((t -> chol(t't))(elty1 <: Complex ? complex.(randn(n, n), randn(n, n)) : randn(n, n)))))


debug && println("elty1: $elty1, A1: $t1")
Expand Down Expand Up @@ -238,7 +238,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
@test ladb ≈ fladb atol=sqrt(eps(real(float(one(elty1)))))*n*n

# Matrix square root
@test sqrt(A1) |> t -> t*t ≈ A1
@test (t -> t*t)(sqrt(A1)) ≈ A1

# naivesub errors
@test_throws DimensionMismatch naivesub!(A1,ones(elty1,n+1))
Expand Down Expand Up @@ -275,7 +275,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa

debug && println("elty1: $elty1, A1: $t1, elty2: $elty2")

A2 = t2(elty2 == Int ? rand(1:7, n, n) : convert(Matrix{elty2}, (elty2 <: Complex ? complex.(randn(n, n), randn(n, n)) : randn(n, n)) |> t -> chol(t't) |> t -> uplo2 == :U ? t : adjoint(t)))
A2 = t2(elty2 == Int ? rand(1:7, n, n) : convert(Matrix{elty2}, (t -> uplo2 == :U ? t : adjoint(t))((t -> chol(t't))(elty2 <: Complex ? complex.(randn(n, n), randn(n, n)) : randn(n, n)))))

# Convert
if elty1 <: Real && !(elty2 <: Integer)
Expand Down Expand Up @@ -397,9 +397,9 @@ end
# Matrix square root
Atn = UpperTriangular([-1 1 2; 0 -2 2; 0 0 -3])
Atp = UpperTriangular([1 1 2; 0 2 2; 0 0 3])
@test sqrt(Atn) |> t->t*t ≈ Atn
@test (t->t*t)(sqrt(Atn)) ≈ Atn
@test typeof(sqrt(Atn)[1,1]) <: Complex
@test sqrt(Atp) |> t->t*t ≈ Atp
@test (t->t*t)(sqrt(Atp)) ≈ Atp
@test typeof(sqrt(Atp)[1,1]) <: Real

Areal = randn(n, n)/2
Expand All @@ -419,7 +419,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
debug && println("\ntype of A: ", eltya, " type of b: ", eltyb, "\n")

debug && println("Solve upper triangular system")
Atri = UpperTriangular(lufact(A)[:U]) |> t -> eltya <: Complex && eltyb <: Real ? real(t) : t # Here the triangular matrix can't be too badly conditioned
Atri = (t -> eltya <: Complex && eltyb <: Real ? real(t) : t)(UpperTriangular(lufact(A)[:U])) # Here the triangular matrix can't be too badly conditioned
b = convert(Matrix{eltyb}, eltya <: Complex ? Matrix(Atri)*ones(n, 2) : Matrix(Atri)*ones(n, 2))
x = Matrix(Atri) \ b

Expand Down Expand Up @@ -447,7 +447,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
end

debug && println("Solve lower triangular system")
Atri = UpperTriangular(lufact(A)[:U]) |> t -> eltya <: Complex && eltyb <: Real ? real(t) : t # Here the triangular matrix can't be too badly conditioned
Atri = (t -> eltya <: Complex && eltyb <: Real ? real(t) : t)(UpperTriangular(lufact(A)[:U])) # Here the triangular matrix can't be too badly conditioned
b = convert(Matrix{eltyb}, eltya <: Complex ? Matrix(Atri)*ones(n, 2) : Matrix(Atri)*ones(n, 2))
x = Matrix(Atri)\b

Expand Down
70 changes: 35 additions & 35 deletions test/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,24 @@ end
@test md"Foo \[bar](baz)" == MD(Paragraph("Foo [bar](baz)"))

# Basic plain (markdown) output
@test md"foo" |> plain == "foo\n"
@test md"foo *bar* baz" |> plain == "foo *bar* baz\n"
@test md"# title" |> plain == "# title\n"
@test md"## section" |> plain == "## section\n"
@test md"## section `foo`" |> plain == "## section `foo`\n"
@test md"""Hello
@test plain(md"foo") == "foo\n"
@test plain(md"foo *bar* baz") == "foo *bar* baz\n"
@test plain(md"# title") == "# title\n"
@test plain(md"## section") == "## section\n"
@test plain(md"## section `foo`") == "## section `foo`\n"
@test plain(md"""Hello

---
World""" |> plain == "Hello\n\n---\n\nWorld\n"
@test md"[*a*](b)" |> plain == "[*a*](b)\n"
@test md"""
World""") == "Hello\n\n---\n\nWorld\n"
@test plain(md"[*a*](b)") == "[*a*](b)\n"
@test plain(md"""
> foo
>
> * bar
>
> ```
> baz
> ```""" |> plain == """> foo\n>\n> * bar\n>\n> ```\n> baz\n> ```\n\n"""
> ```""") == """> foo\n>\n> * bar\n>\n> ```\n> baz\n> ```\n\n"""

# Terminal (markdown) output

Expand All @@ -240,45 +240,45 @@ let doc = Markdown.parse(
end

# HTML output
@test md"foo *bar* baz" |> html == "<p>foo <em>bar</em> baz</p>\n"
@test md"something ***" |> html == "<p>something ***</p>\n"
@test md"# h1## " |> html == "<h1>h1##</h1>\n"
@test md"## h2 ### " |> html == "<h2>h2</h2>\n"
@test md"###### h6" |> html == "<h6>h6</h6>\n"
@test md"####### h7" |> html == "<p>####### h7</p>\n"
@test md" >" |> html == "<blockquote>\n</blockquote>\n"
@test md"1. Hello" |> html == "<ol>\n<li><p>Hello</p>\n</li>\n</ol>\n"
@test md"* World" |> html == "<ul>\n<li><p>World</p>\n</li>\n</ul>\n"
@test md"# title *blah*" |> html == "<h1>title <em>blah</em></h1>\n"
@test md"## title *blah*" |> html == "<h2>title <em>blah</em></h2>\n"
@test md"<https://julialang.org>" |> html == """<p><a href="https://julialang.org">https://julialang.org</a></p>\n"""
@test md"<mailto://[email protected]>" |> html == """<p><a href="mailto://[email protected]">mailto://[email protected]</a></p>\n"""
@test md"<https://julialang.org/not a link>" |> html == "<p>&lt;https://julialang.org/not a link&gt;</p>\n"
@test md"""<https://julialang.org/nota
link>""" |> html == "<p>&lt;https://julialang.org/nota link&gt;</p>\n"
@test md"""Hello
@test html(md"foo *bar* baz") == "<p>foo <em>bar</em> baz</p>\n"
@test html(md"something ***") == "<p>something ***</p>\n"
@test html(md"# h1## ") == "<h1>h1##</h1>\n"
@test html(md"## h2 ### ") == "<h2>h2</h2>\n"
@test html(md"###### h6") == "<h6>h6</h6>\n"
@test html(md"####### h7") == "<p>####### h7</p>\n"
@test html(md" >") == "<blockquote>\n</blockquote>\n"
@test html(md"1. Hello") == "<ol>\n<li><p>Hello</p>\n</li>\n</ol>\n"
@test html(md"* World") == "<ul>\n<li><p>World</p>\n</li>\n</ul>\n"
@test html(md"# title *blah*") == "<h1>title <em>blah</em></h1>\n"
@test html(md"## title *blah*") == "<h2>title <em>blah</em></h2>\n"
@test html(md"<https://julialang.org>") == """<p><a href="https://julialang.org">https://julialang.org</a></p>\n"""
@test html(md"<mailto://[email protected]>") == """<p><a href="mailto://[email protected]">mailto://[email protected]</a></p>\n"""
@test html(md"<https://julialang.org/not a link>") == "<p>&lt;https://julialang.org/not a link&gt;</p>\n"
@test html(md"""<https://julialang.org/nota
link>""") == "<p>&lt;https://julialang.org/nota link&gt;</p>\n"
@test html(md"""Hello

---
World""" |> html == "<p>Hello</p>\n<hr />\n<p>World</p>\n"
@test md"`escape</code>`" |> html == "<p><code>escape&lt;/code&gt;</code></p>\n"
World""") == "<p>Hello</p>\n<hr />\n<p>World</p>\n"
@test html(md"`escape</code>`") == "<p><code>escape&lt;/code&gt;</code></p>\n"

@test md"""
@test html(md"""
code1

code2
""" |> html == "<pre><code>code1\n\ncode2</code></pre>\n" # single code block
""") == "<pre><code>code1\n\ncode2</code></pre>\n" # single code block

# @test md"""
# @test html(md"""
# - Foo
# ---
# - Bar""" |> html == "<ul>\n<li>Foo</li>\n</ul>\n<hr />\n<ul>\n<li>Bar</li>\n</ul>\n"
@test md"""
# - Bar""") == "<ul>\n<li>Foo</li>\n</ul>\n<hr />\n<ul>\n<li>Bar</li>\n</ul>\n"
@test html(md"""
h1
===
h2
---
not
== =""" |> html == "<h1>h1</h1>\n<h2>h2</h2>\n<p>not &#61;&#61; &#61;</p>\n"
== =""") == "<h1>h1</h1>\n<h2>h2</h2>\n<p>not &#61;&#61; &#61;</p>\n"

# Latex output
book = md"""
Expand Down
Loading