New answers tagged

0

TypeScript is another typed language that supports intersection types T & U (along with union types T | U). Here's an example cited from their documentation page about advanced types: function extend<T, U>(first: T, second: U): T & U { let result = <T & U>{}; for (let id in first) { (<any>result)[id] = (<any&...


3

I don't like using inheritance for this, because the API is going to be clunky. You will loose the nice functional chaining when you use Either if you wrap it in Task, because then, you will need to await it after every call. Instead I would opt in to either create EitherTask, that is Either which is asynchronous inside or even go step further and create ...


2

One possible option public class ActualApiResultWrapper : Either<IApiErrorEnum, IEnumerable<ActualApiResultDto>> { } Task<ActualApiResultWrapper> GetSeveral(); Then the next result, OtherApiResult... public class OtherApiResultWrapper : Either<IApiErrorEnum, IEnumerable<OtherApiResultDto>> { }


1

You can reduce verbosity by using exceptions, which is the idiomatic and established way of handling error conditions in C#. You are basically introducing a form of typed exceptions (like Java) or typed error codes on top of a language with unchecked exceptions. This is bound to be more verbose, and in particular you can't use try/catch constructs to handle ...


2

Some food for thought. Overloads are traditionally done at compile time. You're talking about doing runtime differentiation of overloads, or in other words, introducing a runtime dispatch to the selection of the overload. There are several things of interest. First, most languages with static type systems that do runtime dispatch (e.g. for virtual or ...


1

A very similar approach is common in object-oriented languages. There, it's called function overloading and it means that you have multiple distinct functions with the same name, but different signatures. These languages don't assign type to the group of functions with the same name, but I think one way to look at it is that it's a tuple (or, more formally, ...



Top 50 recent answers are included