Feature Request: yield
with return values
#2207
Unanswered
ncthbrt
asked this question in
Language Ideas
Replies: 3 comments
-
Relevant: |
Beta Was this translation helpful? Give feedback.
0 replies
-
Apologies. Missed that proposal.
…On Fri, 8 Feb 2019, 18:44 HaloFour ***@***.*** wrote:
Relevant:
#1957 <#1957>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://github.com/dotnet/csharplang/issues/2207#issuecomment-461866294>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AISSWRmTGRZ_j0i8KtpD7WbKA7PUI-Kdks5vLal8gaJpZM4awbvK>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm afraid I really don't understand this proposal, although I would definitely like to. It would be really useful if you added some code samples! |
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.
-
Currently C# supports the use of
yield return SomeValue;
andyield break;
however it does not supportvar returnValue = yield return SomeValue;
JavaScript generators functions support this form, which turns out to be highly useful for building monadic workflows.
If C# supports
yield return
with return values, it would allow one to build what is effectively F# computation expressions.A concrete example of where this would be useful would be when designing an Akka actor. Instead of having to create mock actors and simulate responses when unit testing, one could define a stateless monadic actor API which is executed by the Akka runtime, and when testing iterate over the actor, making assertions about requests to send messages to other actors and injecting return values for other API calls.
The game engine Unity is another example of where this feature would be useful. Unity uses yield for coroutines. Having yield return values would make coroutines more powerful.
Difficulties with implementing this feature request would be that it would be quite difficult to figure out how modify the enumerable API to retain typesafety of return values and that the underlying state machine implementation may no longer work as AST wise it would be a nested clojure.
Beta Was this translation helpful? Give feedback.
All reactions