From 2a293c2a9c80c09c58bed2cf9c9073d651c18133 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Thu, 31 Jan 2019 05:47:27 -0500 Subject: [PATCH 1/2] add !=(x) <=(x) >=(x) <(x) >(x) --- base/operators.jl | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/base/operators.jl b/base/operators.jl index becbe2cce0a53..0977e5dcb90b4 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -927,6 +927,56 @@ used to implement specialized methods. """ ==(x) = Fix2(==, x) +""" + !=(x) + +Create a function that compares its argument to `x` using [`!=`](@ref), i.e. +a function equivalent to `y -> y != x`. +The returned function is of type `Base.Fix2{typeof(!=)}`, which can be +used to implement specialized methods. +""" +!=(x) = Fix2(!=, x) + +""" + >=(x) + +Create a function that compares its argument to `x` using [`>=`](@ref), i.e. +a function equivalent to `y -> y >= x`. +The returned function is of type `Base.Fix2{typeof(>=)}`, which can be +used to implement specialized methods. +""" +>=(x) = Fix2(>=, x) + +""" + <=(x) + +Create a function that compares its argument to `x` using [`<=`](@ref), i.e. +a function equivalent to `y -> y <= x`. +The returned function is of type `Base.Fix2{typeof(<=)}`, which can be +used to implement specialized methods. +""" +<=(x) = Fix2(<=, x) + +""" + >(x) + +Create a function that compares its argument to `x` using [`>`](@ref), i.e. +a function equivalent to `y -> y > x`. +The returned function is of type `Base.Fix2{typeof(>)}`, which can be +used to implement specialized methods. +""" +>(x) = Fix2(>, x) + +""" + <(x) + +Create a function that compares its argument to `x` using [`<`](@ref), i.e. +a function equivalent to `y -> y < x`. +The returned function is of type `Base.Fix2{typeof(<)}`, which can be +used to implement specialized methods. +""" +<(x) = Fix2(<, x) + """ splat(f) From fb51479901d7b40388ecae6e73eb7aef11f13a66 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Thu, 31 Jan 2019 05:49:29 -0500 Subject: [PATCH 2/2] add tests for curried comparisons --- test/operators.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/operators.jl b/test/operators.jl index fc574cafa654b..3a265dff7ccc8 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -196,3 +196,20 @@ end @test fx(y) == x / y @test fy(x) == x / y end + + +@testset "curried comparisons" begin + eql5 = (==)(5) + neq5 = (!=)(5) + gte5 = (>=)(5) + lte5 = (<=)(5) + gt5 = (>)(5) + lt5 = (<)(5) + + @test eql5(5) && !eql5(0) + @test neq5(6) && !neq5(5) + @test gte5(5) && gte5(6) + @test lte5(5) && lte5(4) + @test gt5(6) && !gt5(5) + @test lt5(4) && !lt5(5) +end