Skip to content

Commit aba344a

Browse files
committed
Use pattern variables
1 parent 59fa912 commit aba344a

13 files changed

Lines changed: 14 additions & 28 deletions

File tree

src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ public Tail tail() {
263263

264264
@Override
265265
public final boolean equals(Object other) {
266-
if (other instanceof HCons) {
267-
HCons<?, ?> that = (HCons<?, ?>) other;
266+
if (other instanceof HCons<?, ?> that) {
268267
return this.head.equals(that.head)
269268
&& this.tail.equals(that.tail);
270269
}

src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ public Collection<Object> values() {
162162

163163
@Override
164164
public boolean equals(Object other) {
165-
if (other instanceof HMap) {
166-
HMap that = (HMap) other;
165+
if (other instanceof HMap that) {
167166
return Objects.equals(this.table, that.table);
168167
}
169168
return false;

src/main/java/com/jnape/palatable/lambda/functor/builtin/Lazy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ public A value() {
182182
tuple((Lazy<Object>) this, new LinkedList<>());
183183
@SuppressWarnings("unchecked")
184184
A a = (A) trampoline(into((source, flatMaps) -> {
185-
if (source instanceof Compose<?>) {
186-
Compose<?> nested = (Compose<?>) source;
185+
if (source instanceof Compose<?> nested) {
187186
flatMaps.push(nested.flatMap);
188187
return recurse(tuple(nested.source, flatMaps));
189188
}

src/main/java/com/jnape/palatable/lambda/internal/iteration/DroppingIterable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public final class DroppingIterable<A> implements Iterable<A> {
77
private final Iterable<A> as;
88

99
public DroppingIterable(int n, Iterable<A> as) {
10-
while (as instanceof DroppingIterable) {
11-
DroppingIterable<A> nested = (DroppingIterable<A>) as;
10+
while (as instanceof DroppingIterable<A> nested) {
1211
as = nested.as;
1312
n += nested.n;
1413
}

src/main/java/com/jnape/palatable/lambda/internal/iteration/FilteringIterable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public final class FilteringIterable<A> implements Iterable<A> {
1515

1616
public FilteringIterable(Fn1<? super A, ? extends Boolean> predicate, Iterable<A> as) {
1717
List<Fn1<? super A, ? extends Boolean>> predicates = new ArrayList<>(singletonList(predicate));
18-
while (as instanceof FilteringIterable) {
19-
FilteringIterable<A> nested = (FilteringIterable<A>) as;
18+
while (as instanceof FilteringIterable<A> nested) {
2019
predicates.addAll(0, nested.predicates);
2120
as = nested.as;
2221
}

src/main/java/com/jnape/palatable/lambda/internal/iteration/MappingIterable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public final class MappingIterable<A, B> implements Iterable<B> {
1616
@SuppressWarnings("unchecked")
1717
public MappingIterable(Fn1<? super A, ? extends B> fn, Iterable<A> as) {
1818
List<Fn1<?, ?>> mappers = new ArrayList<>(singletonList(fn));
19-
while (as instanceof MappingIterable<?, ?>) {
20-
MappingIterable<?, ?> nested = (MappingIterable<?, ?>) as;
19+
while (as instanceof MappingIterable<?, ?> nested) {
2120
as = (Iterable<A>) nested.as;
2221
mappers.addAll(0, nested.mappers);
2322
}

src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedDroppingIterable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public final class PredicatedDroppingIterable<A> implements Iterable<A> {
1111

1212
public PredicatedDroppingIterable(Fn1<? super A, ? extends Boolean> predicate, Iterable<A> as) {
1313
ImmutableQueue<Fn1<? super A, ? extends Boolean>> predicates = ImmutableQueue.singleton(predicate);
14-
while (as instanceof PredicatedDroppingIterable) {
15-
PredicatedDroppingIterable<A> nested = (PredicatedDroppingIterable<A>) as;
14+
while (as instanceof PredicatedDroppingIterable<A> nested) {
1615
as = nested.as;
1716
predicates = nested.predicates.concat(predicates);
1817
}

src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedTakingIterable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public final class PredicatedTakingIterable<A> implements Iterable<A> {
1515

1616
public PredicatedTakingIterable(Fn1<? super A, ? extends Boolean> predicate, Iterable<A> as) {
1717
List<Fn1<? super A, ? extends Boolean>> predicates = new ArrayList<>(singletonList(predicate));
18-
while (as instanceof PredicatedTakingIterable) {
19-
PredicatedTakingIterable<A> nested = (PredicatedTakingIterable<A>) as;
18+
while (as instanceof PredicatedTakingIterable<A> nested) {
2019
predicates.addAll(0, nested.predicates);
2120
as = nested.as;
2221
}

src/main/java/com/jnape/palatable/lambda/internal/iteration/RateLimitingIterable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public final class RateLimitingIterable<A> implements Iterable<A> {
1515

1616
public RateLimitingIterable(Iterable<A> as, Set<Tuple3<Long, Duration, Fn0<Instant>>> rateLimits) {
1717
Set<Tuple3<Long, Duration, Fn0<Instant>>> combinedRateLimits = new HashSet<>(rateLimits);
18-
if (as instanceof RateLimitingIterable) {
19-
RateLimitingIterable<A> inner = (RateLimitingIterable<A>) as;
18+
if (as instanceof RateLimitingIterable<A> inner) {
2019
combinedRateLimits.addAll(inner.rateLimits);
2120
as = inner.as;
2221
}

src/main/java/com/jnape/palatable/lambda/internal/iteration/ReversingIterable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public final class ReversingIterable<A> implements Iterable<A> {
88

99
public ReversingIterable(Iterable<A> as) {
1010
boolean reverse = true;
11-
while (as instanceof ReversingIterable) {
12-
ReversingIterable<A> nested = (ReversingIterable<A>) as;
11+
while (as instanceof ReversingIterable<A> nested) {
1312
as = nested.as;
1413
reverse = !nested.reverse;
1514
}

0 commit comments

Comments
 (0)