@@ -2357,4 +2357,53 @@ enum OneEnum implements SomeInterface {
23572357 enum SecondEnum implements SomeInterface {
23582358 A1 , A2 , A3 ;
23592359 }
2360+
2361+
2362+ @ Test
2363+ public void shouldLeftJoinNotIncludeRightKeysThatDontExistOnTheLeft () {
2364+ Seq <Integer > left = of (1 , 2 , 5 );
2365+ Seq <String > right = of ("1" , "2" , "6" );
2366+ Seq <Tuple2 <Integer , Option <String >>> joined =
2367+ left .leftJoin (right , Function .identity (), Integer ::parseInt );
2368+ assertThat (joined ).containsExactly (
2369+ Tuple .of (1 , Option .of ("1" )),
2370+ Tuple .of (2 , Option .of ("2" )),
2371+ Tuple .of (5 , Option .none ())
2372+ );
2373+ }
2374+
2375+ @ Test
2376+ public void shouldLeftJoinOnlyIncludeTheFirstMatchingKeyFromTheRight () {
2377+ Seq <Integer > left = of (1 , 2 , 5 );
2378+ Seq <String > right = of ("1" , "2" , "55" , "5" );
2379+ Seq <Tuple2 <Integer , Option <String >>> joined =
2380+ left .leftJoin (right , Function .identity (), s -> Integer .parseInt (s .substring (0 , 1 )));
2381+ assertThat (joined ).containsExactly (
2382+ Tuple .of (1 , Option .of ("1" )),
2383+ Tuple .of (2 , Option .of ("2" )),
2384+ Tuple .of (5 , Option .of ("55" ))
2385+ );
2386+ }
2387+
2388+ @ Test
2389+ public void shouldLeftJoinNotHaveAnyRightElementsWhenRightIsEmpty () {
2390+ Seq <Integer > left = of (1 , 2 , 5 );
2391+ Seq <String > right = empty ();
2392+ Seq <Tuple2 <Integer , Option <String >>> joined =
2393+ left .leftJoin (right , Function .identity (), s -> Integer .parseInt (s .substring (0 , 1 )));
2394+ assertThat (joined ).containsExactly (
2395+ Tuple .of (1 , Option .none ()),
2396+ Tuple .of (2 , Option .none ()),
2397+ Tuple .of (5 , Option .none ())
2398+ );
2399+ }
2400+
2401+ @ Test
2402+ public void shouldLeftJoinReturnEmptySeqWhenLeftIsEmpty () {
2403+ Seq <Integer > left = empty ();
2404+ Seq <String > right = of ("1" , "2" , "6" );
2405+ Seq <Tuple2 <Integer , Option <String >>> joined =
2406+ left .leftJoin (right , Function .identity (), Integer ::parseInt );
2407+ assertThat (joined ).isEmpty ();
2408+ }
23602409}
0 commit comments