Skip to content

Commit f4e4482

Browse files
committed
cleaner mapS and mapB implementations
1 parent 810773b commit f4e4482

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

  • src/main/java/com/jnape/palatable/lambda/lens

‎src/main/java/com/jnape/palatable/lambda/lens/Lens.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.function.BiFunction;
1010
import java.util.function.Function;
1111

12-
import static com.jnape.palatable.lambda.functions.builtin.fn1.Id.id;
1312
import static com.jnape.palatable.lambda.lens.Lens.Simple.adapt;
1413
import static com.jnape.palatable.lambda.lens.functions.Over.over;
1514
import static com.jnape.palatable.lambda.lens.functions.Set.set;
@@ -214,7 +213,7 @@ default <R> Lens<R, T, A, B> contraMap(Function<? super R, ? extends S> fn) {
214213
* @return the new lens
215214
*/
216215
default <R> Lens<R, T, A, B> mapS(Function<? super R, ? extends S> fn) {
217-
return compose(lens(fn, (r, t) -> t));
216+
return lens(view(this).compose(fn), (r, b) -> set(this, b, fn.apply(r)));
218217
}
219218

220219
/**
@@ -247,7 +246,7 @@ default <C> Lens<S, T, C, B> mapA(Function<? super A, ? extends C> fn) {
247246
* @return the new lens
248247
*/
249248
default <Z> Lens<S, T, A, Z> mapB(Function<? super Z, ? extends B> fn) {
250-
return andThen(lens(id(), (a, z) -> fn.apply(z)));
249+
return lens(view(this), (s, z) -> set(this, fn.apply(z), s));
251250
}
252251

253252
/**

0 commit comments

Comments
 (0)