Skip to content

Commit 1707283

Browse files
committed
inequality functions all take right-hand side argument first
1 parent 7b48751 commit 1707283

File tree

20 files changed

+82
-80
lines changed

20 files changed

+82
-80
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
99
- ***Breaking Change***: `Absent` moved to `semigroup.builtin` package
1010
- ***Breaking Change***: `Effect#accept()` is now the required method to implement in the functional interface
1111
- ***Breaking Change***: `Fn0#apply()` is now the required method to implement in the functional interface
12+
- ***Breaking Change***: `GTBy`, `GT`, `LTBy`, `LT`, `GTEBy`, `GTE`, `LTEBy`, and `LTE` take the right-hand side first for more intuitive partial application
1213
- `RightAny` overload returns `Monoid`
1314
- monoids now all fold with respect to `foldMap`
1415
- monoid folding now implicitly starts with the identity, regardless of iterable population

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/GT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ private GT() {
2323
}
2424

2525
@Override
26-
public Boolean apply(A x, A y) {
27-
return gtBy(id(), x, y);
26+
public Boolean apply(A y, A x) {
27+
return gtBy(id(), y, x);
2828
}
2929

3030
@SuppressWarnings("unchecked")
3131
public static <A extends Comparable<A>> GT<A> gt() {
3232
return INSTANCE;
3333
}
3434

35-
public static <A extends Comparable<A>> Predicate<A> gt(A x) {
36-
return GT.<A>gt().apply(x);
35+
public static <A extends Comparable<A>> Predicate<A> gt(A y) {
36+
return GT.<A>gt().apply(y);
3737
}
3838

39-
public static <A extends Comparable<A>> Boolean gt(A x, A y) {
40-
return gt(x).apply(y);
39+
public static <A extends Comparable<A>> Boolean gt(A y, A x) {
40+
return gt(y).apply(x);
4141
}
4242
}

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/GTE.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ private GTE() {
2323
}
2424

2525
@Override
26-
public Boolean apply(A x, A y) {
27-
return gteBy(id(), x, y);
26+
public Boolean apply(A y, A x) {
27+
return gteBy(id(), y, x);
2828
}
2929

3030
@SuppressWarnings("unchecked")
3131
public static <A extends Comparable<A>> GTE<A> gte() {
3232
return INSTANCE;
3333
}
3434

35-
public static <A extends Comparable<A>> Predicate<A> gte(A x) {
36-
return GTE.<A>gte().apply(x);
35+
public static <A extends Comparable<A>> Predicate<A> gte(A y) {
36+
return GTE.<A>gte().apply(y);
3737
}
3838

39-
public static <A extends Comparable<A>> Boolean gte(A x, A y) {
40-
return gte(x).apply(y);
39+
public static <A extends Comparable<A>> Boolean gte(A y, A x) {
40+
return gte(y).apply(x);
4141
}
4242
}

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/LT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ private LT() {
2323
}
2424

2525
@Override
26-
public Boolean apply(A x, A y) {
27-
return ltBy(id(), x, y);
26+
public Boolean apply(A y, A x) {
27+
return ltBy(id(), y, x);
2828
}
2929

3030
@SuppressWarnings("unchecked")
3131
public static <A extends Comparable<A>> LT<A> lt() {
3232
return INSTANCE;
3333
}
3434

35-
public static <A extends Comparable<A>> Predicate<A> lt(A x) {
36-
return LT.<A>lt().apply(x);
35+
public static <A extends Comparable<A>> Predicate<A> lt(A y) {
36+
return LT.<A>lt().apply(y);
3737
}
3838

39-
public static <A extends Comparable<A>> Boolean lt(A x, A y) {
40-
return lt(x).apply(y);
39+
public static <A extends Comparable<A>> Boolean lt(A y, A x) {
40+
return lt(y).apply(x);
4141
}
4242
}

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2/LTE.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ private LTE() {
2323
}
2424

2525
@Override
26-
public Boolean apply(A x, A y) {
27-
return lteBy(id(), x, y);
26+
public Boolean apply(A y, A x) {
27+
return lteBy(id(), y, x);
2828
}
2929

3030
@SuppressWarnings("unchecked")
3131
public static <A extends Comparable<A>> LTE<A> lte() {
3232
return INSTANCE;
3333
}
3434

35-
public static <A extends Comparable<A>> Predicate<A> lte(A x) {
36-
return LTE.<A>lte().apply(x);
35+
public static <A extends Comparable<A>> Predicate<A> lte(A y) {
36+
return LTE.<A>lte().apply(y);
3737
}
3838

39-
public static <A extends Comparable<A>> Boolean lte(A x, A y) {
40-
return lte(x).apply(y);
39+
public static <A extends Comparable<A>> Boolean lte(A y, A x) {
40+
return lte(y).apply(x);
4141
}
4242
}

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/GTBy.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private GTBy() {
2525
}
2626

2727
@Override
28-
public Boolean apply(Function<? super A, ? extends B> compareFn, A x, A y) {
28+
public Boolean apply(Function<? super A, ? extends B> compareFn, A y, A x) {
2929
return compareFn.apply(x).compareTo(compareFn.apply(y)) > 0;
3030
}
3131

@@ -48,11 +48,11 @@ public static <A, B extends Comparable<B>> BiPredicate<A, A> gtBy(Function<? sup
4848
return GTBy.<A, B>gtBy().apply(fn);
4949
}
5050

51-
public static <A, B extends Comparable<B>> Predicate<A> gtBy(Function<? super A, ? extends B> fn, A x) {
52-
return GTBy.<A, B>gtBy(fn).apply(x);
51+
public static <A, B extends Comparable<B>> Predicate<A> gtBy(Function<? super A, ? extends B> fn, A y) {
52+
return GTBy.<A, B>gtBy(fn).apply(y);
5353
}
5454

55-
public static <A, B extends Comparable<B>> Boolean gtBy(Function<? super A, ? extends B> fn, A x, A y) {
56-
return gtBy(fn, x).apply(y);
55+
public static <A, B extends Comparable<B>> Boolean gtBy(Function<? super A, ? extends B> fn, A y, A x) {
56+
return gtBy(fn, y).apply(x);
5757
}
5858
}

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/GTEBy.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ private GTEBy() {
2828
}
2929

3030
@Override
31-
public Boolean apply(Function<? super A, ? extends B> compareFn, A x, A y) {
32-
return GTBy.<A, B>gtBy(compareFn).or(cmpEqBy(compareFn)).apply(x, y);
31+
public Boolean apply(Function<? super A, ? extends B> compareFn, A y, A x) {
32+
return GTBy.<A, B>gtBy(compareFn).or(cmpEqBy(compareFn)).apply(y, x);
3333
}
3434

3535
@Override
@@ -38,8 +38,8 @@ public BiPredicate<A, A> apply(Function<? super A, ? extends B> compareFn) {
3838
}
3939

4040
@Override
41-
public Predicate<A> apply(Function<? super A, ? extends B> compareFn, A x) {
42-
return Fn3.super.apply(compareFn, x)::apply;
41+
public Predicate<A> apply(Function<? super A, ? extends B> compareFn, A y) {
42+
return Fn3.super.apply(compareFn, y)::apply;
4343
}
4444

4545
@SuppressWarnings("unchecked")
@@ -51,11 +51,11 @@ public static <A, B extends Comparable<B>> BiPredicate<A, A> gteBy(Function<? su
5151
return GTEBy.<A, B>gteBy().apply(fn);
5252
}
5353

54-
public static <A, B extends Comparable<B>> Predicate<A> gteBy(Function<? super A, ? extends B> fn, A x) {
55-
return GTEBy.<A, B>gteBy(fn).apply(x);
54+
public static <A, B extends Comparable<B>> Predicate<A> gteBy(Function<? super A, ? extends B> fn, A y) {
55+
return GTEBy.<A, B>gteBy(fn).apply(y);
5656
}
5757

58-
public static <A, B extends Comparable<B>> Boolean gteBy(Function<? super A, ? extends B> fn, A x, A y) {
59-
return gteBy(fn, x).apply(y);
58+
public static <A, B extends Comparable<B>> Boolean gteBy(Function<? super A, ? extends B> fn, A y, A x) {
59+
return gteBy(fn, y).apply(x);
6060
}
6161
}

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/LTBy.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private LTBy() {
2525
}
2626

2727
@Override
28-
public Boolean apply(Function<? super A, ? extends B> compareFn, A x, A y) {
28+
public Boolean apply(Function<? super A, ? extends B> compareFn, A y, A x) {
2929
return compareFn.apply(x).compareTo(compareFn.apply(y)) < 0;
3030
}
3131

@@ -35,8 +35,8 @@ public BiPredicate<A, A> apply(Function<? super A, ? extends B> compareFn) {
3535
}
3636

3737
@Override
38-
public Predicate<A> apply(Function<? super A, ? extends B> compareFn, A x) {
39-
return Fn3.super.apply(compareFn, x)::apply;
38+
public Predicate<A> apply(Function<? super A, ? extends B> compareFn, A y) {
39+
return Fn3.super.apply(compareFn, y)::apply;
4040
}
4141

4242
@SuppressWarnings("unchecked")
@@ -48,11 +48,11 @@ public static <A, B extends Comparable<B>> BiPredicate<A, A> ltBy(Function<? sup
4848
return LTBy.<A, B>ltBy().apply(fn);
4949
}
5050

51-
public static <A, B extends Comparable<B>> Predicate<A> ltBy(Function<? super A, ? extends B> fn, A x) {
52-
return LTBy.<A, B>ltBy(fn).apply(x);
51+
public static <A, B extends Comparable<B>> Predicate<A> ltBy(Function<? super A, ? extends B> fn, A y) {
52+
return LTBy.<A, B>ltBy(fn).apply(y);
5353
}
5454

55-
public static <A, B extends Comparable<B>> Boolean ltBy(Function<? super A, ? extends B> fn, A x, A y) {
56-
return ltBy(fn, x).apply(y);
55+
public static <A, B extends Comparable<B>> Boolean ltBy(Function<? super A, ? extends B> fn, A y, A x) {
56+
return ltBy(fn, y).apply(x);
5757
}
5858
}

src/main/java/com/jnape/palatable/lambda/functions/builtin/fn3/LTEBy.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ private LTEBy() {
2828
}
2929

3030
@Override
31-
public Boolean apply(Function<? super A, ? extends B> compareFn, A x, A y) {
32-
return LTBy.<A, B>ltBy(compareFn).or(cmpEqBy(compareFn)).apply(x, y);
31+
public Boolean apply(Function<? super A, ? extends B> compareFn, A y, A x) {
32+
return LTBy.<A, B>ltBy(compareFn).or(cmpEqBy(compareFn)).apply(y, x);
3333
}
3434

3535
@Override
@@ -38,8 +38,8 @@ public BiPredicate<A, A> apply(Function<? super A, ? extends B> compareFn) {
3838
}
3939

4040
@Override
41-
public Predicate<A> apply(Function<? super A, ? extends B> compareFn, A x) {
42-
return Fn3.super.apply(compareFn, x)::apply;
41+
public Predicate<A> apply(Function<? super A, ? extends B> compareFn, A y) {
42+
return Fn3.super.apply(compareFn, y)::apply;
4343
}
4444

4545
@SuppressWarnings("unchecked")
@@ -51,11 +51,11 @@ public static <A, B extends Comparable<B>> BiPredicate<A, A> lteBy(Function<? su
5151
return LTEBy.<A, B>lteBy().apply(fn);
5252
}
5353

54-
public static <A, B extends Comparable<B>> Predicate<A> lteBy(Function<? super A, ? extends B> fn, A x) {
55-
return LTEBy.<A, B>lteBy(fn).apply(x);
54+
public static <A, B extends Comparable<B>> Predicate<A> lteBy(Function<? super A, ? extends B> fn, A y) {
55+
return LTEBy.<A, B>lteBy(fn).apply(y);
5656
}
5757

58-
public static <A, B extends Comparable<B>> Boolean lteBy(Function<? super A, ? extends B> fn, A x, A y) {
59-
return lteBy(fn, x).apply(y);
58+
public static <A, B extends Comparable<B>> Boolean lteBy(Function<? super A, ? extends B> fn, A y, A x) {
59+
return lteBy(fn, y).apply(x);
6060
}
6161
}

src/main/java/com/jnape/palatable/lambda/iteration/RateLimitingIterator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import static com.jnape.palatable.lambda.adt.Try.trying;
1717
import static com.jnape.palatable.lambda.functions.builtin.fn1.Size.size;
1818
import static com.jnape.palatable.lambda.functions.builtin.fn2.Filter.filter;
19-
import static com.jnape.palatable.lambda.functions.builtin.fn2.GT.gt;
2019
import static com.jnape.palatable.lambda.functions.builtin.fn2.GTE.gte;
20+
import static com.jnape.palatable.lambda.functions.builtin.fn2.LT.lt;
2121
import static com.jnape.palatable.lambda.functions.builtin.fn2.LTE.lte;
2222
import static com.jnape.palatable.lambda.semigroup.builtin.Max.max;
2323
import static java.lang.Thread.sleep;
@@ -67,8 +67,8 @@ private boolean rateLimitExhaustedInTimeSlice(Tuple3<Long, Duration, Supplier<In
6767
return rateLimit.into((limit, duration, instantSupplier) -> {
6868
Instant timeSliceEnd = instantSupplier.get();
6969
Instant previousTimeSliceEnd = timeSliceEnd.minus(duration);
70-
timeSlicesForRateLimit.removeIf(gt(previousTimeSliceEnd));
71-
return max(0L, limit - size(filter(mark -> gte(mark, previousTimeSliceEnd) && lte(mark, timeSliceEnd), timeSlicesForRateLimit))) == 0;
70+
timeSlicesForRateLimit.removeIf(lt(previousTimeSliceEnd));
71+
return max(0L, limit - size(filter(mark -> lte(mark, previousTimeSliceEnd) && gte(mark, timeSliceEnd), timeSlicesForRateLimit))) == 0;
7272
});
7373
}
7474

0 commit comments

Comments
 (0)