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

Monad classes in C# #39851

Closed
giorgiozoppi opened this issue Jul 29, 2019 · 10 comments

Comments

@giorgiozoppi
Copy link

commented Jul 29, 2019

Feature request: Support for some basic monads as maybe, either monads directly in the corefx.
This will enable more functional domain and concurrent domain application. Several libraries are available but it is still missing an official one.

An example possible will be:

 public Either<EmailStatus, EmailMessage> Validate(EmailMessage message)
        {
            List<EmailMessage> listMessages = new List<EmailMessage>() {message};
            var filterItemCount = listMessages.Where(msg => HasValidFrom(msg))
                .Where(msgTo => HasValidContacts(msgTo.EmailTo))
                .Where(msgCc => HasOptionalValidContacts(msgCc.EmailCarbonCopy))
                .Where(msgBcc => HasOptionalValidContacts(msgBcc.EmailCarbonCopy)).Count();

            return (filterItemCount > 0)
                ? Either.Right<EmailStatus, EmailMessage>(() => message)
                : Either.Left<EmailStatus, EmailMessage>(() => CreateMailStatus(message));

        }

This is a logic for email header validation.

@scalablecory

This comment has been minimized.

Copy link
Member

commented Jul 29, 2019

There's a pretty popular issue on the C# repo for this: dotnet/csharplang#399

@danmosemsft

This comment has been minimized.

Copy link
Member

commented Jul 29, 2019

@giorgiozoppi C# language requests should go into the dotnet/csharplang repo. I don't have the power to move issues there, so I'll close this and let you decide whether to add to that existing issue or open a new one. Thanks for the suggestion!

@MgSam

This comment has been minimized.

Copy link

commented Jul 30, 2019

Erm- despite the wording of the title, I don't think he's asking for a language feature. I think he's asking for a library in the BCL. Please correct me if I'm misreading.

@scalablecory

This comment has been minimized.

Copy link
Member

commented Jul 30, 2019

Agreed @MgSam

@scalablecory scalablecory reopened this Jul 30, 2019

@stephentoub stephentoub added this to the Future milestone Jul 31, 2019

@giorgiozoppi

This comment has been minimized.

Copy link
Author

commented Aug 4, 2019

I am asking for a library. Sorry for the misleading title. We have just a lot of features in this language. For example this library could be useful as well in TPL.DataFlow and since it will be lazy, In Haskell some monads classes are in the “Standard Prelude". It will be nice to have System.Functional.Monad namespaces that it will might include:

  • Either
  • MayBe (or a stronger variant of NullOptional)
  • Reader<E,T>
  • Writer
  • IO
    This will help a lot of user to create an immutable business logic.
@garfbradaz

This comment has been minimized.

Copy link
Collaborator

commented Aug 4, 2019

I still dont know what a Monad is 😅

@JarnoNijboer

This comment has been minimized.

Copy link

commented Aug 5, 2019

I am asking for a library. Sorry for the misleading title. We have just a lot of features in this language. For example this library could be useful as well in TPL.DataFlow and since it will be lazy, In Haskell some monads classes are in the “Standard Prelude". It will be nice to have System.Functional.Monad namespaces that it will might include:

  • Either
  • MayBe (or a stronger variant of NullOptional)
  • Reader<E,T>
  • Writer
  • IO
    This will help a lot of user to create an immutable business logic.

If you want Functional types, maybe you could use the FSharp.Core package?

@giorgiozoppi

This comment has been minimized.

Copy link
Author

commented Aug 8, 2019

Makes sense.

@giorgiozoppi

This comment has been minimized.

Copy link
Author

commented Aug 8, 2019

I would close this issue.

@karelz karelz modified the milestones: Future, 5.0 Aug 9, 2019

@MaceWindu

This comment has been minimized.

Copy link

commented Aug 9, 2019

if you are looking for library, you should check this one https://github.com/louthy/language-ext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.