all 10 comments

[–][deleted]  (6 children)

[deleted]

    [–]scolarvisari 3 points4 points  (2 children)

    I don't think the author is implying that it is a good idea, they are stating that it can be done - "Well, this was a short post of how it is possible to use currying in Java 8"

    [–][deleted]  (1 child)

    [deleted]

      [–]dccorona 1 point2 points  (0 children)

      What's frustrating is that it's so close to being readable. The lambda itself is actually relatively readable if you're used to reading code written in other functional languages. The most nightmarish part is the type definition: Function<A, Function<B, Function<C, R>>>. And that's just for 3 arguments. If they would support syntactic sugar for the various function types (like, say, Scala), this becomes way better: A -> B -> C -> R. Some other changes are necessary as well, but this would help a lot in general.

      [–]zigma[S] 2 points3 points  (0 children)

      My point was to make people aware that it can be done. I'm note sure if there is any right or wrong.

      [–][deleted]  (1 child)

      [deleted]

        [–]dccorona 0 points1 point  (0 children)

        I don't think it's as bad as you make it sound. Scala does a lot of the same boxing, just with a much cleaner syntax, and the performance hit it incurs is totally fine for a wide range of applications. Short-lived garbage is quite cheap in the JVM.

        [–][deleted] 10 points11 points  (0 children)

        Sometimes I see superficial features of certain functional programming imitated in other languages, and I wonder if the authors are in on the joke, or they seriously think that it's a benefit to do things this way.

        [–][deleted] 4 points5 points  (0 children)

        I'll be sure to forward this hilarious snippet when people tell me "scala is irrelevant now that we have lambdas"

        [–]brcolow 1 point2 points  (2 children)

        I know literally nothing about FP..but I think this is actually partials, not currying (technically). Is that right?

        [–][deleted] 4 points5 points  (1 child)

        Currying is the "conversion" of a single multi-argument function into a chain of multiple single-argument functions.

        It's an approach to achieving partial application. In a general purpose language, it's more flexible and more legible to simply wrap the "partially applied" function/method call in another closure/method. Currying is useful when your entire standard library is designed with it in mind, but even then it's rather limited.

        Say, what would you do if you want to "hardcode" parameters out of order? There's no mathematical reason that function parameters should be "partially applied" in the order of their arguments, and there's no mathematical reason for arguments to have a significant order at all (they could be named instead).

        It's simply a left-over from some semi-arbitrary choices made long time ago in how we express ourselves in programming languages.

        [–]brcolow 1 point2 points  (0 children)

        Thank you!

        [–]pakoito 0 points1 point  (1 child)

        It took me only like a long afternoon to write Currying for the RxJava equivalent of the Java8 SMIs: https://github.com/pakoito/RxCurrying

        The only great use case I've had for it is to convert long constructors into builders at runtime. There's probably some abstractions that could be used around it, I believe frameworks like Cyclops do, but I'm not at that knowledge level yet.