How to work with IEnumerable and the yield keyword? yield == Error "The body cannot be an iterator block because Result<IEnumerable<T>, Error> is not an iterator
#472
Unanswered
jeffward01
asked this question in
Q&A
Replies: 2 comments
|
Also, if anyone has suggestions on how I can improve my code and avoid the |
0 replies
|
Here: #354 I see you can perform a workaround of: return Result.Success<IEnumerable<TEntity>, Error>(arrayOfEntities);So now it compiles like this: // this is valid code, no errors (I have not testing it yet)
protected override Result<IEnumerable<TEntity>, Error> ReplaceRange(
IEnumerable<TEntity> entities,
PersistOptions persistOptions)
{
var arrayOfEntities = entities.ToArray();
foreach (var entity in arrayOfEntities)
{
entity.AsMaybe()
.ToResultWithErrorCode(DomainErrors.NullOrEmpty.EntityWasNull)
.Ensure(_ => entity.HasPrimaryKey(), DomainErrors.NotFound.MissingPrimaryKey)
.Tap(this.AttachEntity);
}
this.CommitIfAllowed(persistOptions);
return Result.Success<IEnumerable<TEntity>, Error>(arrayOfEntities);
}But now I have lost the power of the keyword Is it possible to use |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I feel like im doing something wrong... I know you want to wrap your Methods in
Result<T, E>so that you know if they failed or succeeded, but when it comes toIEnumerablespecifically using theyieldkeyword - does it work differently?I searched all of the issues, and code, and did not find anything that could answer my question:
The examples I have seen show something like:
IEnumerable<Result<TEntity, Error>>-- but when I look at that, I see this:IEnumerable<>, so I don't know if the Method call was a success or failResult<TEntity, Error>- so I can see if each individual iterator result was asuccessorfailureI asked a similar question to this regarding
IAsyncEnumerablehereI'm relatively new to proper Functional programming, in the past I have just used
Maybe<>, and now im embracing it more.There must be something im missing with the usage of the
yieldkeywordQuestion
What is the proper way to return
IEnumerablefrom a method usingyieldto achieve a continuous returned data-stream?All reactions