Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curried versions? #3

Open
GrahamCampbell opened this issue Jul 19, 2019 · 3 comments
Open

Curried versions? #3

GrahamCampbell opened this issue Jul 19, 2019 · 3 comments

Comments

@GrahamCampbell
Copy link

Neat little package. After a skim of the examples, I immediately thought that currying would be neat. Like:

BEFORE:

$iter = Iter::pipe(Gen::from(PEOPLE), [
    Pipe::pluck('age'),
    Pipe::reduce('max'),
    Pipe::switch(function (int $maxAge) {
        return Gen::range(1, $maxAge);
    }),
]);

AFTER:

$iter = Iter::pipe(Gen::from(PEOPLE), [
    Pipe::pluck('age'),
    Pipe::reduce('max'),
    Pipe::switch(Gen::range(1)),
]);

The only problem with this is that it's not possible to encode optional params. Perhaps explicitly have two methods, and take the step first?

Pipe::switch(Gen::rangeWithStep(3)(1))

@jeremeamia
Copy link
Owner

Short closures would be nice here:
Pipe::switch(fn(int $maxAge) => Gen::range(1, $maxAge))
Maybe next year. :-)

I have a partial function application function that could work:
Pipe::switch(Func::apply([Gen::class, 'range'], 1))
Still not the smoothest, but no function definition.

Not sure how often currying would be needed with range() though. It wasn't the most practical of examples.

@GrahamCampbell
Copy link
Author

Hmmm. I guess I was looking for a way to have the nicest possible syntax.

@GrahamCampbell
Copy link
Author

What about if the default was curried, and there was a mechanism to uncurry?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants