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

Improve implicit partial application #841

Closed
shilkazx opened this issue Jun 7, 2024 · 2 comments
Closed

Improve implicit partial application #841

shilkazx opened this issue Jun 7, 2024 · 2 comments

Comments

@shilkazx
Copy link

shilkazx commented Jun 7, 2024

Allow multiple reference of implicit partial.
What we can do is:

>>> [0, 1] |> .[1]
1

But we can't do this:

>>> [0, 1] |> .[1] + .[0]
 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'operator.itemgetter' and 'operator.itemgetter'

A nagging crossover could work, but why not improve the implicit partial:

>>> [0, 1] |> =>_[1] + _[0]
1
@evhub
Copy link
Owner

evhub commented Jun 7, 2024

Implicit partials are intended to be for simple, straightforward operations that can't easily be built out of other operations, not to replace lambdas completely. That being said, Coconut does actually have an easy way to write this without using a lambda (this style is known as point-free programming) using the lift built-in:

>>> [0, 1] |> lift(+)(.[1], .[0])
1

or:

>>> [0, 1] |> .[1] `lift(+)` .[0]
1

@evhub evhub closed this as completed Jun 7, 2024
@shilkazx
Copy link
Author

shilkazx commented Jun 7, 2024

Oh, it does implement the feature but using 'lift' under such circumstances is weirder and more cumbersome than implicit lambda.
Anyway, thanks for your good advice and I really love coconut.

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

No branches or pull requests

2 participants