Add Validation Applicative
Issue #35
new
I have sketched a possible approach to implementing a Validation Applicative for Fugue.
At the moment it is written using JDK8 lambdas; however, I don't believe this is required for correctness, just legibility.
I am interested in comments and critique.
Comments (8)
-
-
// lifts(?) public static <EE, A, R> Validation<EE, R> lift1( Validation<EE, A> fa, Function<A,R> f) { return fa.map(f); } public static <EE, A, B, R> Validation<EE, R> lift2( SemiGroup<EE> s, Validation<EE, A> fa, Validation<EE, B> fb, Function<A,Function<B,R>> f) { return fa.match( failure -> failure.accumulate(s, fb), success -> lift1(fb, f.apply(success.getValue()))); } // accumulate protected <R> Validation<EE, R> accumulate(SemiGroup<EE> s, Validation<EE, ?> vb) { return accLoop(s, v -> v.failure(), vb); } protected <R> Validation<EE, R> accumulate(SemiGroup<EE> s, Validation<EE, ?> vb, Validation<EE, ?> vc, Validation<EE, ?> vd) { return accLoop(s, v -> v.accumulate(s, vc, vd), vb); } protected <R> Validation<EE, R> accLoop(SemiGroup<EE> s, Function<Failure<EE, ?>, Validation<EE, R>> acc, Validation<EE, ?> v) { return v.fold(ee -> acc.apply(failure(s.add(e, ee))), x -> acc.apply(this)); }
-
Possible additional behaviours:
- leftmap(Function<A,B>)/bimap(Function<E,C>, Function<A,B)
- extend maybe interface
- success biased foreach
<*
or*>
chooseleft, chooseright given two validations ??- a swap Validation<A,B> to Validation<B,A>
-
Account Deactivated reporter An initial implementation of a Validation Applicative.
See Issue #35 for details.
→ <<cset 8e920fb3dde1>>
-
Since Validation is isomorphic to Either, I think the approach of FJ - Validation just being a wrapper around Either with specialized/renamed methods - is good to maximize code reuse.
-
- removed responsible
-
Is this likely to make it into a (soon) future version? Would be very useful
-
I'm not currently looking at it. I'd be happy to work though an implementation in PR though.
- Log in to comment
Base classes: