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

Uniform Function Call Syntax (UFCS) #21482

Open
2 tasks
KhalyutkinVictor opened this issue May 10, 2024 · 2 comments
Open
2 tasks

Uniform Function Call Syntax (UFCS) #21482

KhalyutkinVictor opened this issue May 10, 2024 · 2 comments
Labels
Feature Request This issue is made to request a feature.

Comments

@KhalyutkinVictor
Copy link

KhalyutkinVictor commented May 10, 2024

Describe the feature

One of the most pleasured feature from D. I really interesting can it be implemented in V?

This syntax gives you really nice expirience when you write in functional style. This syntax also can allow to remove this form of methods declaration fn (a Type) foo_bar(s string) string and write simply fn foo_bar(a Type, s string), so all the way how functions should be declared start being more consistent

Use Case

D examples

// UFCS style
10.iota
    .filter!(a => a % 2 == 0)
    .writeln();

// Traditional style:
writeln(filter!(a => a % 2 == 0)
               (iota(10)));

Proposed Solution

I like how it works in D
https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs

Other Information

It can be done even without BC (need to discus)

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

0.4.5

Environment details (OS name and version, etc.)

linux, Ubuntu 22.04.2 LTS
macos, Sonoma 14.4.1

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@KhalyutkinVictor KhalyutkinVictor added the Feature Request This issue is made to request a feature. label May 10, 2024
@heyimtcn
Copy link

heyimtcn commented May 11, 2024

this could be implemented as the pipe operator in elixir where:

other_function() |> new_function() |> baz() |> bar() |> foo()

is the same as

foo(bar(baz(new_function(other_function()))))

so v can still be methods with the same syntax

i'm personally very much against the idea of replacing methods with functions, they allow the type's methods to be with the type which is much more organised and intuitive, whereas having all methods be functions would lead modules to be much more cluttered and making it almost impossible to differentiate traditional methods and functions apart

@KhalyutkinVictor
Copy link
Author

Im really cant imagine situation where i need to differ methods and functions. In this case we can easily extend other code without any breakings because we cant touch private things in that functions, and it even allows to extend regular types like int or string.
It is like mixins

Pipe operator is ok, but it will add new pipe operator, UFCS just reuse .. Also UFCS has clearest syntax even in simple situations. I mean you write subject.op(arg), but in other case you woud write op(subject, arg) or subject |> op(arg), for me first way is the clearest one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is made to request a feature.
Projects
None yet
Development

No branches or pull requests

2 participants