Closed Bug 863329 Opened 11 years ago Closed 11 years ago

Implement `partialRight` on `sdk/lang/functional`

Categories

(Add-on SDK Graveyard :: General, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: zer0, Unassigned)

Details

Partially related to bug 863315: in IRC Irakli agreed about the refactoring of `sdk/event/utils`, and also pointed out some interesting use of having a partial application of those function that bound the `callback` instead of the `target`.

That could be actually useful in general, even in the standard generics where the `callback` is the second / last argument. We should have a `partial` function that returns a new function with the arguments bound starting from the right, instead of the left.
Irakli, I'd like to have your feedback about it. How do you think it should logically behaves? For example, let's having a `log` function with three arguments:

    function log(a, b, c) {
        console.log(a, b, c);
    }

And then:

    let plog = partialRight(10);

What should be the output in those cases?

    plog();
    plog(1);
    plog(1, 2);
    plog(1, 2, 3);

We can approach in at least two / three different ways, and you have more experience in other functional languages, so maybe you have some good suggestion about it.
Flags: needinfo?(rFobic)
of course it is `plog = partialRight(log, 10)`.
Most functonal js libs expose something function called `flip` that just returns fn with flipped args, so you could use same partial there too. I think that's a way to go, although I'd close this as won't fix until we actually need this.
Flags: needinfo?(rFobic)
Let's reopen when we'll actually need such an utility, so far need for this is just theoretical.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.