News for hackers. Stuff that matters.
Re:Currying in JavaScript by okasaki on Sunday September 19, 2021 @08:21AM (#28583749)
I don't see why that's better than the good old for loop.

    errors = list()
    for user in users:
        if not sendEmail(user.email)
            errors.append("Error sending emails")
Re:Currying in JavaScript by p2t2p on Sunday September 19, 2021 @09:56AM (#28584337)
For me, the functional/pipeline/call chain style changes perception from "how" to "what".

Because I say "what" do to do without going into details of "how" I feel like I have spent less mental capacity reading this portion of code.

However, it does require your transformations to be simple and composable, shove a giant multi-line lambda in there it yes, the loop will be better.

Re:Currying in JavaScript by neurotrace on Sunday September 19, 2021 @08:37AM (#28583837)
The example I gave was contrived. I frequently find myself modeling much of my logic as a series of data transformations. The more I can model logic like this, the easier it is to test.

For what it's worth, your example doesn't map 1-to-1 to the intention of what I wrote. Doing it in a more imperative style, I'd have to write

    emails = list()
    for user in users:
        emails.push(user.email)
    res = sendEmail emails
    if res.IsError:
        Error("Error sending emails")
    else:
        res
(excuse my pseudo Python)
Re:Currying in JavaScript by BiteCode_dev on Sunday September 19, 2021 @10:01AM (#28584374)
Excuses accepted. Imperative Python would really look like:

    try:
        return sendEmail(user.email for user in users)
    except IsError:
        Error("Error sending emails") # if it does something
I agree FP pipelines are nice, but not everything needs it.
Re:Currying in JavaScript by HugoDaniel on Sunday September 19, 2021 @09:13AM (#28584077)
nice one, however shouldn't good old for loops be done in ALGOL instead?