Probably not what you were looking for, but the following feels like a more
direct usage of lambdas.  Apologies for not trying it in Java 8, I
embarrassingly do not have an install of that handy at the moment.  (This
is Scala.)

    List.range(0, math.pow(5,4).intValue).map(x => Integer.toString(x,
5)).map(_.toCharArray)

To get the exact order of the answers you showed would take a little
fiddling, of course, but the idea should translate easily enough.  (Unless,
of course, I made a mistake.  Very likely.)





On Mon, Aug 18, 2014 at 5:52 PM, clay <[email protected]> wrote:

> I did permutations of two [0..4] values. Extending to three/four should be
> straight forward.
>
> Haskell, do notation version:
> do { a <- [0..4]; b <- [0..4]; [(a, b)] }
>
> Haskell, bind version:
> [0..4] >>= (\a -> [0..4] >>= (\b -> [(a, b)]))
>
> Scala, for comprehension (just like Haskell's do notation):
> for (a <- 0 until 4; b <- 0 until 4) yield (a,b)
>
> Java 8 Stream/Lambda version:
> Stream<AbstractMap.SimpleImmutableEntry<Integer, Integer>> s1 =
> IntStream.rangeClosed(0, 4).boxed().flatMap(a -> IntStream.rangeClosed(0,
> 4).mapToObj(b -> new AbstractMap.SimpleImmutableEntry<Integer, Integer>(a,
> b)));
> List<AbstractMap.SimpleImmutableEntry<Integer, Integer>> l1 =
> s1.collect(Collectors.toList());
>
> Clearly, the Java 8 version is far clumsier than the others. The biggest
> hold ups with Java are the lack of tuples, the primitive/object divide, and
> then the lack of flatMap syntactic sugar like Haskell's do or Scala's for.
>
> With this type of functional programming exercise, Java 8 is a big step up
> from Java 7, but far short of Scala or Haskell.
>
> Also, as much as I like this group, I'd recommend stackexchange as a
> better alternative for this type of focused question with a direct answer.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Java Posse" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/javaposse.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Java 
Posse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/javaposse.
For more options, visit https://groups.google.com/d/optout.

Reply via email to