99import static java .util .Collections .singletonList ;
1010
1111public final class MappingIterable <A , B > implements Iterable <B > {
12- private final Iterable as ;
13- private final List <Function > mappers ;
12+ private final Iterable < A > as ;
13+ private final List <Function <?, ?> > mappers ;
1414
1515 @ SuppressWarnings ("unchecked" )
1616 public MappingIterable (Function <? super A , ? extends B > fn , Iterable <A > as ) {
17- List <Function > mappers = new ArrayList <>(singletonList (fn ));
18- while (as instanceof MappingIterable ) {
17+ List <Function <?, ?> > mappers = new ArrayList <>(singletonList (fn ));
18+ while (as instanceof MappingIterable <?, ?> ) {
1919 MappingIterable <?, ?> nested = (MappingIterable <?, ?>) as ;
20- as = (Iterable ) nested .as ;
20+ as = (Iterable < A > ) nested .as ;
2121 mappers .addAll (0 , nested .mappers );
2222 }
2323 this .as = as ;
@@ -27,7 +27,8 @@ public MappingIterable(Function<? super A, ? extends B> fn, Iterable<A> as) {
2727 @ Override
2828 @ SuppressWarnings ("unchecked" )
2929 public Iterator <B > iterator () {
30- Function fnComposedOnTheHeap = o -> foldLeft ((x , fn ) -> fn .apply (x ), o , mappers );
31- return new MappingIterator <>(fnComposedOnTheHeap , as .iterator ());
30+ Function <Object , Object > fnComposedOnTheHeap = a -> foldLeft ((x , fn ) -> ((Function <Object , Object >) fn ).apply (x ),
31+ a , mappers );
32+ return new MappingIterator <>((Function <? super A , ? extends B >) fnComposedOnTheHeap , as .iterator ());
3233 }
3334}
0 commit comments