From 212727cdc4aaa3221763580f15d42cfe198bcc1c Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Mon, 19 Oct 2015 04:08:57 -0700 Subject: [PATCH] Remove uses of |> chaining from base the usual syntax for function application is faster and more generic packages can use chaining if they like, but best for base to pick a style and use it consistently --- base/dates/periods.jl | 4 +- base/docs/Docs.jl | 4 +- base/docs/utils.jl | 6 +-- base/markdown/Common/block.jl | 6 +-- base/markdown/GitHub/GitHub.jl | 2 +- base/markdown/GitHub/table.jl | 2 +- base/markdown/parse/util.jl | 2 +- base/markdown/render/terminal/formatting.jl | 4 +- doc/manual/documentation.rst | 4 +- doc/stdlib/base.rst | 2 +- test/docs.jl | 8 +-- test/libgit2.jl | 2 +- test/linalg/matmul.jl | 8 +-- test/linalg/triangular.jl | 34 +++++++++--- test/markdown.jl | 60 ++++++++++----------- test/sparsedir/cholmod.jl | 2 +- 16 files changed, 84 insertions(+), 66 deletions(-) diff --git a/base/dates/periods.jl b/base/dates/periods.jl index 9f0c7bb9e58a5..9c8daf129750a 100644 --- a/base/dates/periods.jl +++ b/base/dates/periods.jl @@ -211,8 +211,8 @@ for op in (:.+, :.-) end return Z end - ($op){P<:GeneralPeriod}(x::GeneralPeriod,Y::StridedArray{P}) = ($op)(Y,x) |> ($op_) - ($op_){P<:GeneralPeriod}(x::GeneralPeriod,Y::StridedArray{P}) = ($op)(Y,x) |> ($op_) + ($op){P<:GeneralPeriod}(x::GeneralPeriod,Y::StridedArray{P}) = $op_(($op)(Y,x)) + ($op_){P<:GeneralPeriod}(x::GeneralPeriod,Y::StridedArray{P}) = $op_(($op)(Y,x)) ($op_){P<:GeneralPeriod}(Y::StridedArray{P},x::GeneralPeriod) = ($op)(Y,x) ($op_){P<:GeneralPeriod, Q<:GeneralPeriod}(X::StridedArray{P}, Y::StridedArray{Q}) = reshape(CompoundPeriod[($op_)(X[i],Y[i]) for i in eachindex(X, Y)], promote_shape(size(X),size(Y))) diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index acad83bc90515..24bb9ce3f0fb3 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -481,11 +481,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. diff --git a/base/docs/utils.jl b/base/docs/utils.jl index 160280da0d85b..7e3da8d1f50e2 100644 --- a/base/docs/utils.jl +++ b/base/docs/utils.jl @@ -193,7 +193,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 @@ -293,9 +293,9 @@ moduleusings(mod) = ccall(:jl_module_usings, Any, (Any,), mod) filtervalid(names) = filter(x->!ismatch(r"#", x), map(string, names)) accessible(mod::Module) = - [names(mod, true, true); + filtervalid(unique([names(mod, true, true); map(names, moduleusings(mod))...; - builtins] |> unique |> filtervalid + builtins])) completions(name) = fuzzysort(name, accessible(current_module())) completions(name::Symbol) = completions(string(name)) diff --git a/base/markdown/Common/block.jl b/base/markdown/Common/block.jl index b5d715991e23c..b421ce4b87887 100644 --- a/base/markdown/Common/block.jl +++ b/base/markdown/Common/block.jl @@ -61,7 +61,7 @@ function hashheader(stream::IO, md::MD) return false if c != '\n' # Empty header - h = readline(stream) |> strip + h = strip(readline(stream)) h = match(r"(.*?)( +#+)?$", h).captures[1] buffer = IOBuffer() print(buffer, h) @@ -76,11 +76,11 @@ end function setextheader(stream::IO, md::MD) withstream(stream) do eatindent(stream) || return false - header = readline(stream) |> strip + header = strip(readline(stream)) header == "" && return false eatindent(stream) || return false - underline = readline(stream) |> strip + underline = strip(readline(stream)) length(underline) < 3 && return false u = underline[1] u in "-=" || return false diff --git a/base/markdown/GitHub/GitHub.jl b/base/markdown/GitHub/GitHub.jl index c0ed6b9b036f8..aed2ef1bde33b 100644 --- a/base/markdown/GitHub/GitHub.jl +++ b/base/markdown/GitHub/GitHub.jl @@ -20,7 +20,7 @@ function fencedcode(stream::IO, block::MD) line_start = position(stream) if startswith(stream, string(ch) ^ n) if !startswith(stream, string(ch)) - push!(block, Code(flavor, takebuf_string(buffer) |> chomp)) + push!(block, Code(flavor, chomp(takebuf_string(buffer)))) return true else seek(stream, line_start) diff --git a/base/markdown/GitHub/table.jl b/base/markdown/GitHub/table.jl index baedbdf987eaa..846b554b36b15 100644 --- a/base/markdown/GitHub/table.jl +++ b/base/markdown/GitHub/table.jl @@ -7,7 +7,7 @@ end function parserow(stream::IO) withstream(stream) do - line = readline(stream) |> chomp + line = chomp(readline(stream)) row = split(line, "|") length(row) == 1 && return row[1] == "" && shift!(row) diff --git a/base/markdown/parse/util.jl b/base/markdown/parse/util.jl index f6e43217bdc94..7b973bcd8e4ae 100644 --- a/base/markdown/parse/util.jl +++ b/base/markdown/parse/util.jl @@ -45,7 +45,7 @@ function linecontains(io::IO, chars; allow_whitespace = true, eat = true, allowempty = false) start = position(io) - l = readline(io) |> chomp + l = chomp(readline(io)) length(l) == 0 && return allowempty result = allowempty diff --git a/base/markdown/render/terminal/formatting.jl b/base/markdown/render/terminal/formatting.jl index 1d14f1d60be21..d831191790754 100644 --- a/base/markdown/render/terminal/formatting.jl +++ b/base/markdown/render/terminal/formatting.jl @@ -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, " ") @@ -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 diff --git a/doc/manual/documentation.rst b/doc/manual/documentation.rst index 864d2479825a4..4539ff1c8d544 100644 --- a/doc/manual/documentation.rst +++ b/doc/manual/documentation.rst @@ -372,11 +372,11 @@ Examining it's definition should serve as an example of how to use ``@__doc__`` .. code-block:: julia 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. diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index cd74b8f9407e7..c261c6766fdde 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -773,7 +773,7 @@ System .. data:: DevNull Used in a stream redirect to discard all data written to it. Essentially equivalent to /dev/null on Unix or NUL on Windows. - Usage: ``run(`cat test.txt` |> DevNull)`` + Usage: ``run(pipeline(`cat test.txt`, DevNull))`` .. function:: success(command) diff --git a/test/docs.jl b/test/docs.jl index 9d2a915afe906..34ed71e95abeb 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -276,11 +276,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" @@ -289,11 +289,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" diff --git a/test/libgit2.jl b/test/libgit2.jl index 161db390b18e3..f33b6f79c82eb 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -126,7 +126,7 @@ temp_dir() do dir # set a remote branch branch = "upstream" - LibGit2.GitRemote(repo, branch, repo_url) |> finalize + finalize(LibGit2.GitRemote(repo, branch, repo_url)) config = joinpath(cache_repo, ".git", "config") lines = split(open(readall, config, "r"), "\n") diff --git a/test/linalg/matmul.jl b/test/linalg/matmul.jl index 7698424580099..c7f11c2163d0f 100644 --- a/test/linalg/matmul.jl +++ b/test/linalg/matmul.jl @@ -13,10 +13,10 @@ for i = 1:10 @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 Array(Float64, 5, 0) |> t -> t't == zeros(0,0) - @test Array(Float64, 5, 0) |> t -> t*t' == zeros(5,5) - @test Array(Complex128, 5, 0) |> t -> t't == zeros(0,0) - @test Array(Complex128, 5, 0) |> t -> t*t' == zeros(5,5) + @test (t -> t't)(Array(Float64, 5, 0)) == zeros(0,0) + @test (t -> t*t')(Array(Float64, 5, 0)) == zeros(5,5) + @test (t -> t't)(Array(Complex128, 5, 0)) == zeros(0,0) + @test (t -> t*t')(Array(Complex128, 5, 0)) == zeros(5,5) end # 2x2 diff --git a/test/linalg/triangular.jl b/test/linalg/triangular.jl index 51a25a98ce4e3..9758a8620ff34 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -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(full(t), i) for i = 1:3] +@test (t -> [size(t, i) for i = 1:3] == [size(full(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, Complex64, Complex128, BigFloat, Int) @@ -22,7 +22,15 @@ for elty1 in (Float32, Float64, Complex64, Complex128, BigFloat, Int) (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, Val{uplo1}))) + if elty1 == Int + A1 = t1(rand(1:7, n, n)) + elseif elty1 <: Complex + A1 = t1(convert(Matrix{elty1}, + (t -> chol(t't, Val{uplo1}))(complex(randn(n, n), randn(n, n))))) + else + A1 = t1(convert(Matrix{elty1}, + (t -> chol(t't, Val{uplo1}))(randn(n, n)))) + end debug && println("elty1: $elty1, A1: $t1") @@ -206,7 +214,7 @@ for elty1 in (Float32, Float64, Complex64, Complex128, BigFloat, Int) @test_approx_eq_eps det(A1) det(lufact(full(A1))) sqrt(eps(real(float(one(elty1)))))*n*n # Matrix square root - @test sqrtm(A1) |> t->t*t ≈ A1 + @test (t->t*t)(sqrtm(A1)) ≈ A1 # naivesub errors @test_throws DimensionMismatch naivesub!(A1,ones(elty1,n+1)) @@ -243,7 +251,15 @@ for elty1 in (Float32, Float64, Complex64, Complex128, BigFloat, Int) 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, Val{uplo2}))) + if elty2 == Int + A2 = t2(rand(1:7, n, n)) + elseif elty2 <: Complex + A2 = t2(convert(Matrix{elty2}, + (t -> chol(t't, Val{uplo2}))(complex(randn(n, n), randn(n, n))))) + else + A2 = t2(convert(Matrix{elty2}, + (t -> chol(t't, Val{uplo2}))(randn(n, n)))) + end # Convert if elty1 <: Real && !(elty2 <: Integer) @@ -330,9 +346,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 sqrtm(Atn) |> t->t*t ≈ Atn +@test (t->t*t)(sqrtm(Atn)) ≈ Atn @test typeof(sqrtm(Atn)[1,1]) <: Complex -@test sqrtm(Atp) |> t->t*t ≈ Atp +@test (t->t*t)(sqrtm(Atp)) ≈ Atp @test typeof(sqrtm(Atp)[1,1]) <: Real Areal = randn(n, n)/2 @@ -352,7 +368,8 @@ 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)( # Here the triangular matrix can't be too badly conditioned + UpperTriangular(lufact(A)[:U])) b = convert(Matrix{eltyb}, eltya <: Complex ? full(Atri)*ones(n, 2) : full(Atri)*ones(n, 2)) x = full(Atri) \ b @@ -380,7 +397,8 @@ 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)( # Here the triangular matrix can't be too badly conditioned + UpperTriangular(lufact(A)[:U])) b = convert(Matrix{eltyb}, eltya <: Complex ? full(Atri)*ones(n, 2) : full(Atri)*ones(n, 2)) x = full(Atri)\b diff --git a/test/markdown.jl b/test/markdown.jl index 25c67524ca788..bee469960f983 100644 --- a/test/markdown.jl +++ b/test/markdown.jl @@ -56,61 +56,61 @@ foo # 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""" # HTML output -@test md"foo *bar* baz" |> html == "

foo bar baz

\n" -@test md"something ***" |> html == "

something ***

\n" -@test md"# h1## " |> html == "

h1##

\n" -@test md"## h2 ### " |> html == "

h2

\n" -@test md"###### h6" |> html == "
h6
\n" -@test md"####### h7" |> html == "

####### h7

\n" -@test md" >" |> html == "
\n
\n" -@test md"1. Hello" |> html == "
    \n
  1. Hello
  2. \n
\n" -@test md"* World" |> html == "\n" -@test md"# title *blah*" |> html == "

title blah

\n" -@test md"## title *blah*" |> html == "

title blah

\n" -@test md"""Hello +@test html(md"foo *bar* baz") == "

foo bar baz

\n" +@test html(md"something ***") == "

something ***

\n" +@test html(md"# h1## ") == "

h1##

\n" +@test html(md"## h2 ### ") == "

h2

\n" +@test html(md"###### h6") == "
h6
\n" +@test html(md"####### h7") == "

####### h7

\n" +@test html(md" >") == "
\n
\n" +@test html(md"1. Hello") == "
    \n
  1. Hello
  2. \n
\n" +@test html(md"* World") == "\n" +@test html(md"# title *blah*") == "

title blah

\n" +@test html(md"## title *blah*") == "

title blah

\n" +@test html(md"""Hello --- -World""" |> html == "

Hello

\n
\n

World

\n" -@test md"`escape`" |> html == "

escape</code>

\n" +World""") == "

Hello

\n
\n

World

\n" +@test html(md"`escape`") == "

escape</code>

\n" -@test md""" +@test html(md""" code1 code2 -""" |> html == "
code1\n\ncode2
\n" # single code block +""") == "
code1\n\ncode2
\n" # single code block -# @test md""" +# @test html(md""" # - Foo # --- -# - Bar""" |> html == "\n
\n\n" -@test md""" +# - Bar""") == "\n
\n\n" +@test html(md""" h1 === h2 --- not -== =""" |> html == "

h1

\n

h2

\n

not == =

\n" +== =""") == "

h1

\n

h2

\n

not == =

\n" # Latex output book = md""" diff --git a/test/sparsedir/cholmod.jl b/test/sparsedir/cholmod.jl index 37363dafcdf1f..daa39d90da8ea 100644 --- a/test/sparsedir/cholmod.jl +++ b/test/sparsedir/cholmod.jl @@ -385,7 +385,7 @@ for elty in (Float64, Complex{Float64}) @test_approx_eq logdet(ldltfact(A1pd)) logdet(full(A1pd)) @test isposdef(A1pd) @test !isposdef(A1) - @test !isposdef(A1 + A1' |> t -> t - 2eigmax(full(t))*I) + @test !isposdef((t -> t - 2eigmax(full(t))*I)(A1 + A1')) if elty <: Real @test CHOLMOD.issym(Sparse(A1pd, 0))