Skip to content

Commit cc11576

Browse files
committed
Renaming Strong to Cartesian to better reflect the type of strength
1 parent eeb1412 commit cc11576

7 files changed

Lines changed: 65 additions & 64 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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
1212
- ***Breaking Change***: Eliminated all raw types and java11 warnings. This required using capture in unification
1313
parameters for Functor and friends, so nearly every functor's type-signature changed.
14+
- ***Breaking Change***: `Strong` is now called `Cartesian` to better reflect the type of strength
1415
- `IO` is now stack-safe, regardless of whether the composition nests linearly or recursively
1516

1617
### Added

‎src/main/java/com/jnape/palatable/lambda/functions/Fn1.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
44
import com.jnape.palatable.lambda.functor.Applicative;
5-
import com.jnape.palatable.lambda.functor.Strong;
5+
import com.jnape.palatable.lambda.functor.Cartesian;
66
import com.jnape.palatable.lambda.functor.builtin.Lazy;
77
import com.jnape.palatable.lambda.monad.Monad;
88

@@ -20,7 +20,7 @@
2020
* @param <B> The result type
2121
*/
2222
@FunctionalInterface
23-
public interface Fn1<A, B> extends Monad<B, Fn1<A, ?>>, Strong<A, B, Fn1<?, ?>>, Function<A, B> {
23+
public interface Fn1<A, B> extends Monad<B, Fn1<A, ?>>, Cartesian<A, B, Fn1<?, ?>>, Function<A, B> {
2424

2525
/**
2626
* Invoke this function with the given argument.
@@ -131,7 +131,7 @@ default <C> Fn1<A, B> discardR(Applicative<C, Fn1<A, ?>> appB) {
131131
*/
132132
@Override
133133
default <Z> Fn1<Z, B> diMapL(Function<? super Z, ? extends A> fn) {
134-
return (Fn1<Z, B>) Strong.super.<Z>diMapL(fn);
134+
return (Fn1<Z, B>) Cartesian.super.<Z>diMapL(fn);
135135
}
136136

137137
/**
@@ -144,7 +144,7 @@ default <Z> Fn1<Z, B> diMapL(Function<? super Z, ? extends A> fn) {
144144
*/
145145
@Override
146146
default <C> Fn1<A, C> diMapR(Function<? super B, ? extends C> fn) {
147-
return (Fn1<A, C>) Strong.super.<C>diMapR(fn);
147+
return (Fn1<A, C>) Cartesian.super.<C>diMapR(fn);
148148
}
149149

150150
/**
@@ -168,7 +168,7 @@ default <Z, C> Fn1<Z, C> diMap(Function<? super Z, ? extends A> lFn, Function<?
168168
* @return the strengthened {@link Fn1}
169169
*/
170170
@Override
171-
default <C> Fn1<Tuple2<C, A>, Tuple2<C, B>> strengthen() {
171+
default <C> Fn1<Tuple2<C, A>, Tuple2<C, B>> cartesian() {
172172
return t -> t.fmap(this);
173173
}
174174

@@ -177,12 +177,12 @@ default <C> Fn1<Tuple2<C, A>, Tuple2<C, B>> strengthen() {
177177
*/
178178
@Override
179179
default Fn1<A, Tuple2<A, B>> carry() {
180-
return (Fn1<A, Tuple2<A, B>>) Strong.super.carry();
180+
return (Fn1<A, Tuple2<A, B>>) Cartesian.super.carry();
181181
}
182182

183183
@Override
184184
default <Z> Fn1<Z, B> contraMap(Function<? super Z, ? extends A> fn) {
185-
return (Fn1<Z, B>) Strong.super.<Z>contraMap(fn);
185+
return (Fn1<Z, B>) Cartesian.super.<Z>contraMap(fn);
186186
}
187187

188188
/**

‎src/main/java/com/jnape/palatable/lambda/functions/specialized/checked/CheckedFn1.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ default <Z, C> CheckedFn1<T, Z, C> diMap(Function<? super Z, ? extends A> lFn,
112112
* {@inheritDoc}
113113
*/
114114
@Override
115-
default <C> CheckedFn1<T, Tuple2<C, A>, Tuple2<C, B>> strengthen() {
116-
return Fn1.super.<C>strengthen()::apply;
115+
default <C> CheckedFn1<T, Tuple2<C, A>, Tuple2<C, B>> cartesian() {
116+
return Fn1.super.<C>cartesian()::apply;
117117
}
118118

119119
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.jnape.palatable.lambda.functor;
2+
3+
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
4+
5+
import java.util.function.Function;
6+
7+
/**
8+
* {@link Profunctor} strength in the cartesian sense: <code>p a b -&gt; p (c, a) (c, b)</code> for any type
9+
* <code>c</code>.
10+
*
11+
* @param <A> the type of the left parameter
12+
* @param <B> the type of the left parameter
13+
* @param <S> the unification parameter
14+
* @see com.jnape.palatable.lambda.functions.Fn1
15+
*/
16+
public interface Cartesian<A, B, S extends Cartesian<?, ?, S>> extends Profunctor<A, B, S> {
17+
18+
/**
19+
* Pair some type <code>C</code> to this profunctor's carrier types.
20+
*
21+
* @param <C> the paired type
22+
* @return the cartesian-strengthened profunctor
23+
*/
24+
<C> Cartesian<Tuple2<C, A>, Tuple2<C, B>, S> cartesian();
25+
26+
/**
27+
* Pair the covariantly-positioned carrier type with the contravariantly-positioned carrier type. This can be
28+
* thought of as "carrying" or "inspecting" the left parameter.
29+
*
30+
* @return the profunctor with the first parameter carried
31+
*/
32+
default Cartesian<A, Tuple2<A, B>, S> carry() {
33+
return this.<A>cartesian().contraMap(Tuple2::fill);
34+
}
35+
36+
@Override
37+
<Z, C> Cartesian<Z, C, S> diMap(Function<? super Z, ? extends A> lFn, Function<? super B, ? extends C> rFn);
38+
39+
@Override
40+
default <Z> Cartesian<Z, B, S> diMapL(Function<? super Z, ? extends A> fn) {
41+
return (Cartesian<Z, B, S>) Profunctor.super.<Z>diMapL(fn);
42+
}
43+
44+
@Override
45+
default <C> Cartesian<A, C, S> diMapR(Function<? super B, ? extends C> fn) {
46+
return (Cartesian<A, C, S>) Profunctor.super.<C>diMapR(fn);
47+
}
48+
49+
@Override
50+
default <Z> Cartesian<Z, B, S> contraMap(Function<? super Z, ? extends A> fn) {
51+
return (Cartesian<Z, B, S>) Profunctor.super.<Z>contraMap(fn);
52+
}
53+
}

‎src/main/java/com/jnape/palatable/lambda/functor/Strong.java‎

Lines changed: 0 additions & 53 deletions
This file was deleted.

‎src/test/java/com/jnape/palatable/lambda/functions/Fn1Test.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void widen() {
5656
@Test
5757
public void strengthen() {
5858
Fn1<Integer, Integer> add1 = x -> x + 1;
59-
assertEquals(tuple("a", 2), add1.<String>strengthen().apply(tuple("a", 1)));
59+
assertEquals(tuple("a", 2), add1.<String>cartesian().apply(tuple("a", 1)));
6060
}
6161

6262
@Test

‎src/test/java/com/jnape/palatable/lambda/functions/specialized/checked/CheckedFn1Test.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void assignment() {
2222
CheckedFn1<Throwable, String, Integer> diMapL = parseInt.diMapL(id());
2323
CheckedFn1<Throwable, String, Integer> diMapR = parseInt.diMapR(id());
2424
CheckedFn1<Throwable, String, Integer> diMap = parseInt.diMap(id(), id());
25-
CheckedFn1<Throwable, Tuple2<Object, String>, Tuple2<Object, Integer>> strengthen = parseInt.strengthen();
25+
CheckedFn1<Throwable, Tuple2<Object, String>, Tuple2<Object, Integer>> strengthen = parseInt.cartesian();
2626
CheckedFn1<Throwable, String, Tuple2<String, Integer>> carry = parseInt.carry();
2727
CheckedFn1<Throwable, String, Integer> contraMap = parseInt.contraMap(id());
2828
CheckedFn1<Throwable, String, Integer> compose = parseInt.compose(id());

0 commit comments

Comments
 (0)