CSharpFunctionalExtensions icon indicating copy to clipboard operation
CSharpFunctionalExtensions copied to clipboard

Error : Cannot implicitly convert type

Open 77it opened this issue 7 years ago • 1 comments

The following code:

IEnumerable<string> list = new List<string>();
Maybe<IEnumerable<string>> maybeList = list;  // line in error

gives me the error

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'CSharpFunctionalExtensions.Maybe<System.Collections.Generic.IEnumerable>'

Instead, the following code, works perfectly:

List<string> list = new List<string>();
Maybe<IEnumerable<string>> maybeList = list;

Any hint?

77it avatar Aug 23 '18 13:08 77it

I just ran into a similar problem. I noticed there is a From static method on the Maybe type though, and it allowed me to work around this problem:

var thing = Maybe<IThing>.From(other.ContainsKey(key) ? other[key] : null);
// thing is now Maybe of IThing

kitsu avatar Dec 14 '18 23:12 kitsu