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 |
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.
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 toIEnumerable
specifically using theyield
keyword - 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 asuccess
orfailure
I asked a similar question to this regarding
IAsyncEnumerable
hereI'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
yield
keywordQuestion
What is the proper way to return
IEnumerable
from a method usingyield
to achieve a continuous returned data-stream?Beta Was this translation helpful? Give feedback.
All reactions