Proposal: infix functions as pseudo custom operators with redundant brackets #3977
Unanswered
tomschrot
asked this question in
Language Ideas
Replies: 2 comments
-
If you write new Container<int>( 1 )
.alter x => x
.use x => Console.WriteLine(x) How can you tell if its: new Container<int>( 1 )
.alter(x => x)
.use(x => Console.WriteLine(x)) Or new Container<int>( 1 )
.alter(x => x.use(x => Console.WriteLine(x))) ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Did you perhaps mean to remove the dots from the second example? It still has ambiguities though, as Yair pointed out. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everybody
First, please excuse my bumpy English, Im not native English speaking.
After a 2 year excursion into the Kotlin universe, I ended up with good old C# and .NET CORE again. But there are some wistful memories that I really would like to see in C# that could make C# code more compact, less verbose and increase readability. One thing that I had come to appreciate in Kotlin is the ability to define infix functions that can be regarded as sort of custom pseudo operator. The rule is simple, just write a function that has one single parameter and declare it as "infix". Like with C# operator overloading, the brackets become obsolete. Example in standard C#:
`
class Program {
`
Could become like this:
`
class Program {
`
I'm aware that the given example ist not the best one, but I think the idea is clear. (Read about custom operators here 4 Y ago, that should do it...)
It could also be great to adopt the Kotlin lambda notation, but this is another story!
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions