-
Notifications
You must be signed in to change notification settings - Fork 3
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
[RFC] Implement task monad #45
Conversation
@kind = Message::None | ||
|
||
def initialize(proc) | ||
@channel_message = channel_message = Channel::Buffered(Message).new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a workaround to know if a task is finished.
end | ||
end | ||
|
||
def bind(lambda : T -> U) : U forall U |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This don't realy behave like others bind
.
Another name could be used.
spec/monads/task_spec.cr
Outdated
@@ -0,0 +1,43 @@ | |||
require "../spec_helper" | |||
|
|||
class Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An exception cannot be compared.
But the Either
monad will have an Exception.
I think we could create a class who inherit from an Either for this use case.
61fe2c3
to
304612f
Compare
value = proc.call | ||
channel_message.send Message::Value | ||
channel_value.send value | ||
rescue exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be rescue Exception
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, maybe not. Never mind 😅 .
@moba1 can you look at this code ? |
LGTM |
304612f
to
68bde01
Compare
I disagree, there is the Exception problem, I try to fix it now ! :) |
7a38917
to
0c4ea87
Compare
I made a solution :) Take a look |
🙆♂ |
Add the Task monad to the monads shard.
What is
Task
monad ?The
Task
monad permit to run asynchronous action and chain it like a monad.Why Task don't inherit from
Monads::Monad(T)
?The Task monad doesn't have the
fmap
method.Also, it doesn't realy behave like a monad, it could be converted to a monad with
to_either
orto_maybe
.