Skip to content

Commit 329e784

Browse files
committed
Eliminating all raw types
1 parent f076fc8 commit 329e784

186 files changed

Lines changed: 594 additions & 490 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
99
factory methods should continue to work (by simply targeting `Supplier` now instead of an anonymous `IO`), but some
1010
might need to be reworked, and subtyping is obviously no longer supported.
1111
- ***Breaking Change***: `FoldRight` now requires `Lazy` as part of its interface to support short-circuiting operations
12+
- ***Breaking Change***: Eliminated all raw types and java11 warnings. This required using capture in unification
13+
parameters for Functor and friends, so nearly every functor's type-signature changed.
1214
- `IO` is now stack-safe, regardless of whether the composition nests linearly or recursively
1315

1416
### Added

src/main/java/com/jnape/palatable/lambda/adt/Either.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
* @param <L> The left parameter type
3333
* @param <R> The right parameter type
3434
*/
35-
public abstract class Either<L, R> implements CoProduct2<L, R, Either<L, R>>, Monad<R, Either<L, ?>>, Traversable<R, Either<L, ?>>, Bifunctor<L, R, Either> {
35+
public abstract class Either<L, R> implements
36+
CoProduct2<L, R, Either<L, R>>,
37+
Monad<R, Either<L, ?>>,
38+
Traversable<R, Either<L, ?>>,
39+
Bifunctor<L, R, Either<?, ?>> {
3640

3741
private Either() {
3842
}
@@ -125,8 +129,9 @@ public final Either<L, R> filter(Function<? super R, ? extends Boolean> pred,
125129
* @return the Either resulting from applying rightFn to this right value, or this left value if left
126130
*/
127131
@Override
132+
@SuppressWarnings("RedundantTypeArguments")
128133
public <R2> Either<L, R2> flatMap(Function<? super R, ? extends Monad<R2, Either<L, ?>>> rightFn) {
129-
return match(Either::left, rightFn.andThen(Applicative::coerce));
134+
return match(Either::left, rightFn.andThen(Monad<R2, Either<L, ?>>::coerce));
130135
}
131136

132137
@Override
@@ -146,6 +151,7 @@ public final Either<R, L> invert() {
146151
* @return the merged Either
147152
*/
148153
@SafeVarargs
154+
@SuppressWarnings("varargs")
149155
public final Either<L, R> merge(BiFunction<? super L, ? super L, ? extends L> leftFn,
150156
BiFunction<? super R, ? super R, ? extends R> rightFn,
151157
Either<L, R>... others) {
@@ -279,9 +285,10 @@ public final <R2> Either<L, R> discardR(Applicative<R2, Either<L, ?>> appB) {
279285
*/
280286
@Override
281287
@SuppressWarnings("unchecked")
282-
public final <R2, App extends Applicative, TravB extends Traversable<R2, Either<L, ?>>, AppB extends Applicative<R2, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
283-
Function<? super R, ? extends AppB> fn,
284-
Function<? super TravB, ? extends AppTrav> pure) {
288+
public final <R2, App extends Applicative<?, App>, TravB extends Traversable<R2, Either<L, ?>>,
289+
AppB extends Applicative<R2, App>,
290+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super R, ? extends AppB> fn,
291+
Function<? super TravB, ? extends AppTrav> pure) {
285292
return (AppTrav) match(l -> pure.apply((TravB) left(l)), r -> fn.apply(r).fmap(Either::right));
286293
}
287294

src/main/java/com/jnape/palatable/lambda/adt/Maybe.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
* @param <A> the optional parameter type
3333
* @see Optional
3434
*/
35-
public abstract class Maybe<A> implements CoProduct2<Unit, A, Maybe<A>>, Monad<A, Maybe>, Traversable<A, Maybe> {
35+
public abstract class Maybe<A> implements
36+
CoProduct2<Unit, A, Maybe<A>>,
37+
Monad<A, Maybe<?>>,
38+
Traversable<A, Maybe<?>> {
3639

3740
private Maybe() {
3841
}
@@ -131,7 +134,7 @@ public final <B> Maybe<B> fmap(Function<? super A, ? extends B> fn) {
131134
* {@inheritDoc}
132135
*/
133136
@Override
134-
public final <B> Maybe<B> zip(Applicative<Function<? super A, ? extends B>, Maybe> appFn) {
137+
public final <B> Maybe<B> zip(Applicative<Function<? super A, ? extends B>, Maybe<?>> appFn) {
135138
return Monad.super.zip(appFn).coerce();
136139
}
137140

@@ -143,7 +146,7 @@ public final <B> Maybe<B> zip(Applicative<Function<? super A, ? extends B>, Mayb
143146
* @return the zipped {@link Maybe}
144147
*/
145148
@Override
146-
public <B> Lazy<Maybe<B>> lazyZip(Lazy<Applicative<Function<? super A, ? extends B>, Maybe>> lazyAppFn) {
149+
public <B> Lazy<Maybe<B>> lazyZip(Lazy<Applicative<Function<? super A, ? extends B>, Maybe<?>>> lazyAppFn) {
147150
return match(constantly(lazy(nothing())),
148151
a -> lazyAppFn.fmap(maybeF -> maybeF.<B>fmap(f -> f.apply(a)).coerce()));
149152
}
@@ -152,24 +155,25 @@ public <B> Lazy<Maybe<B>> lazyZip(Lazy<Applicative<Function<? super A, ? extends
152155
* {@inheritDoc}
153156
*/
154157
@Override
155-
public final <B> Maybe<B> discardL(Applicative<B, Maybe> appB) {
158+
public final <B> Maybe<B> discardL(Applicative<B, Maybe<?>> appB) {
156159
return Monad.super.discardL(appB).coerce();
157160
}
158161

159162
/**
160163
* {@inheritDoc}
161164
*/
162165
@Override
163-
public final <B> Maybe<A> discardR(Applicative<B, Maybe> appB) {
166+
public final <B> Maybe<A> discardR(Applicative<B, Maybe<?>> appB) {
164167
return Monad.super.discardR(appB).coerce();
165168
}
166169

167170
/**
168171
* {@inheritDoc}
169172
*/
173+
@SuppressWarnings("RedundantTypeArguments")
170174
@Override
171-
public final <B> Maybe<B> flatMap(Function<? super A, ? extends Monad<B, Maybe>> f) {
172-
return match(constantly(nothing()), f.andThen(Applicative::coerce));
175+
public final <B> Maybe<B> flatMap(Function<? super A, ? extends Monad<B, Maybe<?>>> f) {
176+
return match(constantly(nothing()), f.andThen(Monad<B, Maybe<?>>::coerce));
173177
}
174178

175179
/**
@@ -208,9 +212,10 @@ public final Maybe<A> peek(Consumer<A> consumer) {
208212

209213
@Override
210214
@SuppressWarnings("unchecked")
211-
public final <B, App extends Applicative, TravB extends Traversable<B, Maybe>, AppB extends Applicative<B, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
212-
Function<? super A, ? extends AppB> fn,
213-
Function<? super TravB, ? extends AppTrav> pure) {
215+
public final <B, App extends Applicative<?, App>, TravB extends Traversable<B, Maybe<?>>,
216+
AppB extends Applicative<B, App>,
217+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super A, ? extends AppB> fn,
218+
Function<? super TravB, ? extends AppTrav> pure) {
214219
return match(__ -> pure.apply((TravB) Maybe.<B>nothing()), a -> (AppTrav) fn.apply(a).fmap(Maybe::just));
215220
}
216221

@@ -272,11 +277,11 @@ public static <A> Maybe<A> just(A a) {
272277
*/
273278
@SuppressWarnings("unchecked")
274279
public static <A> Maybe<A> nothing() {
275-
return Nothing.INSTANCE;
280+
return (Maybe<A>) Nothing.INSTANCE;
276281
}
277282

278283
private static final class Nothing<A> extends Maybe<A> {
279-
private static final Nothing INSTANCE = new Nothing();
284+
private static final Nothing<?> INSTANCE = new Nothing<>();
280285

281286
private Nothing() {
282287
}

src/main/java/com/jnape/palatable/lambda/adt/These.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ public final <C> These<A, C> pure(C c) {
5757

5858
@Override
5959
@SuppressWarnings("unchecked")
60-
public <C, App extends Applicative, TravB extends Traversable<C, These<A, ?>>, AppB extends Applicative<C, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
61-
Function<? super B, ? extends AppB> fn, Function<? super TravB, ? extends AppTrav> pure) {
60+
public <C, App extends Applicative<?, App>, TravB extends Traversable<C, These<A, ?>>,
61+
AppB extends Applicative<C, App>,
62+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super B, ? extends AppB> fn,
63+
Function<? super TravB, ? extends AppTrav> pure) {
6264
return match(a -> pure.apply((TravB) a(a)),
6365
b -> fn.apply(b).fmap(this::pure).<TravB>fmap(Applicative::coerce).coerce(),
6466
into((a, b) -> fn.apply(b).fmap(c -> both(a, c)).<TravB>fmap(Applicative::coerce).coerce()));

src/main/java/com/jnape/palatable/lambda/adt/Try.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ public <B> Try<T, A> discardR(Applicative<B, Try<T, ?>> appB) {
200200
*/
201201
@Override
202202
@SuppressWarnings("unchecked")
203-
public <B, App extends Applicative, TravB extends Traversable<B, Try<T, ?>>, AppB extends Applicative<B, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
204-
Function<? super A, ? extends AppB> fn, Function<? super TravB, ? extends AppTrav> pure) {
203+
public <B, App extends Applicative<?, App>, TravB extends Traversable<B, Try<T, ?>>,
204+
AppB extends Applicative<B, App>,
205+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super A, ? extends AppB> fn,
206+
Function<? super TravB, ? extends AppTrav> pure) {
205207
return match(t -> pure.apply((TravB) failure(t)),
206208
a -> fn.apply(a).fmap(Try::success).<TravB>fmap(Applicative::coerce).coerce());
207209
}

src/main/java/com/jnape/palatable/lambda/adt/choice/Choice2.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public abstract class Choice2<A, B> implements
3030
CoProduct2<A, B, Choice2<A, B>>,
3131
Monad<B, Choice2<A, ?>>,
32-
Bifunctor<A, B, Choice2>,
32+
Bifunctor<A, B, Choice2<?, ?>>,
3333
Traversable<B, Choice2<A, ?>> {
3434

3535
private Choice2() {
@@ -151,8 +151,10 @@ public final <C> Choice2<A, C> flatMap(Function<? super B, ? extends Monad<C, Ch
151151
*/
152152
@Override
153153
@SuppressWarnings("unchecked")
154-
public <C, App extends Applicative, TravB extends Traversable<C, Choice2<A, ?>>, AppB extends Applicative<C, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
155-
Function<? super B, ? extends AppB> fn, Function<? super TravB, ? extends AppTrav> pure) {
154+
public <C, App extends Applicative<?, App>, TravB extends Traversable<C, Choice2<A, ?>>,
155+
AppB extends Applicative<C, App>,
156+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super B, ? extends AppB> fn,
157+
Function<? super TravB, ? extends AppTrav> pure) {
156158
return match(a -> pure.apply((TravB) a(a)),
157159
b -> fn.apply(b).fmap(Choice2::b).<TravB>fmap(Applicative::coerce).coerce());
158160
}

src/main/java/com/jnape/palatable/lambda/adt/choice/Choice3.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ public <D> Choice3<A, B, D> flatMap(Function<? super C, ? extends Monad<D, Choic
152152
*/
153153
@Override
154154
@SuppressWarnings("unchecked")
155-
public <D, App extends Applicative, TravB extends Traversable<D, Choice3<A, B, ?>>, AppB extends Applicative<D, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
156-
Function<? super C, ? extends AppB> fn, Function<? super TravB, ? extends AppTrav> pure) {
155+
public <D, App extends Applicative<?, App>, TravB extends Traversable<D, Choice3<A, B, ?>>,
156+
AppB extends Applicative<D, App>,
157+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super C, ? extends AppB> fn,
158+
Function<? super TravB, ? extends AppTrav> pure) {
157159
return match(a -> pure.apply((TravB) Choice3.<A, B, D>a(a)).coerce(),
158160
b -> pure.apply((TravB) Choice3.<A, B, D>b(b)).coerce(),
159161
c -> fn.apply(c).fmap(Choice3::c).<TravB>fmap(Applicative::coerce).coerce());

src/main/java/com/jnape/palatable/lambda/adt/choice/Choice4.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ public <E> Choice4<A, B, C, E> flatMap(Function<? super D, ? extends Monad<E, Ch
154154
*/
155155
@Override
156156
@SuppressWarnings("unchecked")
157-
public <E, App extends Applicative, TravB extends Traversable<E, Choice4<A, B, C, ?>>, AppB extends Applicative<E, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
158-
Function<? super D, ? extends AppB> fn, Function<? super TravB, ? extends AppTrav> pure) {
157+
public <E, App extends Applicative<?, App>, TravB extends Traversable<E, Choice4<A, B, C, ?>>,
158+
AppB extends Applicative<E, App>,
159+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super D, ? extends AppB> fn,
160+
Function<? super TravB, ? extends AppTrav> pure) {
159161
return match(a -> pure.apply((TravB) Choice4.<A, B, C, E>a(a)).coerce(),
160162
b -> pure.apply((TravB) Choice4.<A, B, C, E>b(b)).coerce(),
161163
c -> pure.apply((TravB) Choice4.<A, B, C, E>c(c)),

src/main/java/com/jnape/palatable/lambda/adt/choice/Choice5.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ public <F> Choice5<A, B, C, D, F> flatMap(Function<? super E, ? extends Monad<F,
160160
*/
161161
@Override
162162
@SuppressWarnings("unchecked")
163-
public <F, App extends Applicative, TravB extends Traversable<F, Choice5<A, B, C, D, ?>>, AppB extends Applicative<F, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
164-
Function<? super E, ? extends AppB> fn, Function<? super TravB, ? extends AppTrav> pure) {
163+
public <F, App extends Applicative<?, App>, TravB extends Traversable<F, Choice5<A, B, C, D, ?>>,
164+
AppB extends Applicative<F, App>,
165+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super E, ? extends AppB> fn,
166+
Function<? super TravB, ? extends AppTrav> pure) {
165167
return match(a -> pure.apply((TravB) Choice5.<A, B, C, D, F>a(a)).coerce(),
166168
b -> pure.apply((TravB) Choice5.<A, B, C, D, F>b(b)).coerce(),
167169
c -> pure.apply((TravB) Choice5.<A, B, C, D, F>c(c)),

src/main/java/com/jnape/palatable/lambda/adt/choice/Choice6.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ public <G> Choice6<A, B, C, D, E, G> flatMap(
165165
*/
166166
@Override
167167
@SuppressWarnings("unchecked")
168-
public <G, App extends Applicative, TravB extends Traversable<G, Choice6<A, B, C, D, E, ?>>, AppB extends Applicative<G, App>, AppTrav extends Applicative<TravB, App>> AppTrav traverse(
169-
Function<? super F, ? extends AppB> fn, Function<? super TravB, ? extends AppTrav> pure) {
168+
public <G, App extends Applicative<?, App>, TravB extends Traversable<G, Choice6<A, B, C, D, E, ?>>,
169+
AppB extends Applicative<G, App>,
170+
AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super F, ? extends AppB> fn,
171+
Function<? super TravB, ? extends AppTrav> pure) {
170172
return match(a -> pure.apply((TravB) Choice6.<A, B, C, D, E, G>a(a)).coerce(),
171173
b -> pure.apply((TravB) Choice6.<A, B, C, D, E, G>b(b)).coerce(),
172174
c -> pure.apply((TravB) Choice6.<A, B, C, D, E, G>c(c)),

0 commit comments

Comments
 (0)