@@ -347,15 +347,126 @@ public static final class RightProjection<A, B, C> {
347347 private RightProjection (final Either3 <A , B , C > e ) {
348348 this .e = e ;
349349 }
350+ public <X > Either3 <A , B , X > apply (final Either3 <A , B , F <C , X >> e ) {
351+ return e .right ().bind (this ::map );
352+ }
350353
351354 public <X > Either3 <A , B , X > bind (F <C , Either3 <A , B , X >> f ) {
352355 return e .either (a -> left (a ), b -> middle (b ), c -> f .f (c ));
353356 }
354357
358+ public Either3 <A , B , C > either () {
359+ return e ;
360+ }
361+
362+ public boolean exists (final F <C , Boolean > f ) {
363+ return e .either (a -> false , b -> false , c -> f .f (c ));
364+ }
365+
366+ public <X , Y > Option <Either3 <X , Y , C >> filter (final F <C , Boolean > f ) {
367+ return e .either (a -> none (), b -> none (), c -> f .f (c ) ? some (right (c )) : none ());
368+ }
369+
370+ public boolean forall (final F <C , Boolean > f ) {
371+ return e .either (a -> true , b -> true , c -> f .f (c ));
372+ }
373+
374+ public Unit foreach (final F <C , Unit > f ) {
375+ return e .either (a -> unit (), b -> unit (), c -> f .f (c ));
376+ }
377+
378+ public void foreachDoEffect (final Effect1 <C > f ) {
379+ e .either (a -> unit (), b -> unit (), c -> f .toF ().f (c ));
380+ }
381+
382+ public Iterator <C > iterator () {
383+ return toList ().iterator ();
384+ }
385+
355386 public <X > Either3 <A , B , X > map (final F <C , X > f ) {
356387 return e .either (a -> left (a ), b -> middle (b ), c -> right (f .f (c )));
357388 }
358389
390+ public C orValue (final C value ) {
391+ return orValue (() -> value );
392+ }
393+
394+ public C orValue (final F0 <C > f ) {
395+ return e .either (a -> f .f (), b -> f .f (), c -> c );
396+ }
397+
398+ public <X > Either3 <A , B , X > sequence (final Either3 <A , B , X > e ) {
399+ return bind (Function .constant (e ));
400+ }
401+
402+ public Array <C > toArray () {
403+ return e .either (
404+ a -> Array .empty (),
405+ b -> Array .empty (),
406+ c -> Array .single (c )
407+ );
408+ }
409+
410+ public Collection <C > toCollection () {
411+ return toList ().toCollection ();
412+ }
413+
414+ public List <C > toList () {
415+ return e .either (a -> nil (), b -> nil (), c -> single (c ));
416+ }
417+
418+ public Option <C > toOption () {
419+ return e .either (a -> none (), b -> none (), c -> some (c ));
420+ }
421+
422+ public Stream <C > toStream () {
423+ return e .either (a -> Stream .nil (), b -> Stream .nil (), c -> Stream .single (c ));
424+ }
425+
426+ public <X > IO <Either3 <A , B , X >> traverseIO (final F <C , IO <X >> f ) {
427+ return e .either (
428+ a -> IOFunctions .unit (left (a )),
429+ b -> IOFunctions .unit (middle (b )),
430+ c -> f .f (c ).map (Either3 ::right )
431+ );
432+ }
433+
434+ public <X > List <Either3 <A , B , X >> traverseList1 (final F <C , List <X >> f ) {
435+ return e .either (
436+ a -> single (left (a )),
437+ b -> single (middle (b )),
438+ c -> f .f (c ).map (Either3 ::right )
439+ );
440+ }
441+
442+ public <X > Option <Either3 <A , B , X >> traverseOption (final F <C , Option <X >> f ) {
443+ return e .either (
444+ a -> some (left (a )),
445+ b -> some (middle (b )),
446+ c -> f .f (c ).map (Either3 ::right )
447+ );
448+
449+ }
450+
451+ public <X > P1 <Either3 <A , B , X >> traverseP1 (final F <C , P1 <X >> f ) {
452+ return e .either (
453+ a -> p (left (a )),
454+ b -> p (middle (b )),
455+ c -> f .f (c ).map (Either3 ::right )
456+ );
457+
458+ }
459+
460+ public <X > Stream <Either3 <A , B , X >> traverseStream (final F <C , Stream <X >> f ) {
461+ return e .either (
462+ a -> Stream .single (left (a )),
463+ b -> Stream .single (middle (b )),
464+ c -> f .f (c ).map (Either3 ::right )
465+ );
466+
467+ }
468+
469+
359470 }
360471
361472 public static <A , B , C > Either3 <A , B , C > left (A a ) {
0 commit comments