Type aliasing on a generic function definition #1315
-
Hello, I have the following function which works fine: public static Either<Error, DomainObject> ReadValidatedFileBytes(
Func<string, Either<Error, string>> pathValidation,
Func<string, Either<Error, DomainObject>> artefactReader,
string filePath)
{
return Prelude.Right<Error, string >(filePath)
.Bind(pathValidation)
.Bind(artefactReader);
} The definition is however quite verbose. Is it possible to alias a function definition such as
but of course the following does not compile since delegates cannot be converted automatically: public static Either<Error, DomainObject> ReadValidatedFileBytes(
Validator<string> pathValidation,
Validator<string, DomainObject> artefactReader,
string filePath)
{
return Prelude.Right<Error, string >(filePath)
.Bind(pathValidation)
.Bind(artefactReader);
} I am new to the library and FP in general, so trying to browse the library for an existing solution is a bit overwhelming. With kind regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
One quick thing you can do is to replace your Either<Error, *> with Fin<*>. The Fin type is essentially a built-in alias for Either<Error, *> You can convert between them using ToFin() and ToEither() I've never really found typed delegates to help that much with readability. You could consider 'global using' which allows for project-wide aliases? |
Beta Was this translation helpful? Give feedback.
One quick thing you can do is to replace your Either<Error, *> with Fin<*>. The Fin type is essentially a built-in alias for Either<Error, *>
You can convert between them using ToFin() and ToEither()
I've never really found typed delegates to help that much with readability.
You could consider 'global using' which allows for project-wide aliases?