@ SuppressWarnings ( "unchecked" ) public static < T > int traverse ( T list , Functor < ? , T > func ) { if ( list == null ) { return 0 ; } else if ( list instanceof Pair ) { Pair < T , T > pair = ( Pair < T , T > ) list ; func . invoke ( pair . first ) ; return 1 + traverse ( pair . second , func ) ; } else { func . invoke ( list ) ; return 1 ; } }
Traverses an isomorphic list using a Functor . The return values from the functor are discarded .