4 ms·
> Union types Yes, these are missing in C#. > Object literals You could use records[1], or anonymous types[2]. > Functions as first class citizens There's
by delta_p_delta_x 4y ago
> Union types
Yes, these are missing in C#.
> Object literals
You could use records[1], or anonymous types[2].
> Functions as first class citizens
There's delegates[3] and lambda expressions[4]. Is there anything that's missing here that you need?
You can use lambda expressions almost exactly like you might in JS/TS, even omitting the type:
var squared = x => x * x;
And if you want even more functional, you could always use F#.
[1]: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
[2]: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/anonymous-types https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
[3]: https://learn.microsoft.com/en-us/dotnet/api/system?view=net-7.0#delegates https://learn.microsoft.com/en-us/dotnet/api/system?view=net...
[4]: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
- prmph 4y ago> You could use records[1], or anonymous types[2]. Not quite with directness of JS. > There's delegates[3] and lambda expressions[4]. Again you can get something equivalent, but not without some ceremony. It’s not as frictionless as with JS.
- delta_p_delta_x 4y ago> It’s not as frictionless as with JS. I'm not sure how much less friction you want than directly declaring lambdas, or LINQ, or any of the newer functional constructs. Like I said, if you want more functional, there's F#, which is a dialect of ML.
- kaba0 4y agoI think your problem is just structural vs nominal typing, in that you can’t get away from the former.