@@ -11,6 +11,7 @@ import {
1111 map ,
1212 mapLeft ,
1313 match ,
14+ partition ,
1415 Right ,
1516 right ,
1617 sequence ,
@@ -458,4 +459,37 @@ describe('Either - Curried Helpers', () => {
458459 const result = sequence ( eithers ) ;
459460 expect ( result . match ( { left : ( e ) => e , right : ( _ ) => '' } ) ) . toBe ( 'First error' ) ;
460461 } ) ;
462+
463+ it ( 'partition should separate lefts and rights' , ( ) => {
464+ const eithers = [
465+ right < string , number > ( 1 ) ,
466+ left < string , number > ( 'error1' ) ,
467+ right < string , number > ( 2 ) ,
468+ left < string , number > ( 'error2' ) ,
469+ right < string , number > ( 3 ) ,
470+ ] ;
471+ const { lefts, rights } = partition ( eithers ) ;
472+ expect ( rights ) . toEqual ( [ 1 , 2 , 3 ] ) ;
473+ expect ( lefts ) . toEqual ( [ 'error1' , 'error2' ] ) ;
474+ } ) ;
475+
476+ it ( 'partition should return all rights when no lefts' , ( ) => {
477+ const eithers = [ right < string , number > ( 1 ) , right < string , number > ( 2 ) , right < string , number > ( 3 ) ] ;
478+ const { lefts, rights } = partition ( eithers ) ;
479+ expect ( rights ) . toEqual ( [ 1 , 2 , 3 ] ) ;
480+ expect ( lefts ) . toEqual ( [ ] ) ;
481+ } ) ;
482+
483+ it ( 'partition should return all lefts when all fail' , ( ) => {
484+ const eithers = [ left < string , number > ( 'e1' ) , left < string , number > ( 'e2' ) , left < string , number > ( 'e3' ) ] ;
485+ const { lefts, rights } = partition ( eithers ) ;
486+ expect ( lefts ) . toEqual ( [ 'e1' , 'e2' , 'e3' ] ) ;
487+ expect ( rights ) . toEqual ( [ ] ) ;
488+ } ) ;
489+
490+ it ( 'partition should return empty arrays for empty input' , ( ) => {
491+ const { lefts, rights } = partition < string , number > ( [ ] ) ;
492+ expect ( lefts ) . toEqual ( [ ] ) ;
493+ expect ( rights ) . toEqual ( [ ] ) ;
494+ } ) ;
461495} ) ;
0 commit comments