Skip to content
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

Merged
merged 2 commits into from
May 18, 2019
Merged

[RFC] Implement task monad #45

merged 2 commits into from
May 18, 2019

Conversation

alex-lairan
Copy link
Owner

@alex-lairan alex-lairan commented May 13, 2019

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 or to_maybe.

@kind = Message::None

def initialize(proc)
@channel_message = channel_message = Channel::Buffered(Message).new
Copy link
Owner Author

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
Copy link
Owner Author

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.

@@ -0,0 +1,43 @@
require "../spec_helper"

class Exception
Copy link
Owner Author

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.

@alex-lairan alex-lairan force-pushed the feature/add_task branch 2 times, most recently from 61fe2c3 to 304612f Compare May 13, 2019 18:54
value = proc.call
channel_message.send Message::Value
channel_value.send value
rescue exception

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?

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 😅 .

@alex-lairan
Copy link
Owner Author

@moba1 can you look at this code ?

@moba1
Copy link
Collaborator

moba1 commented May 16, 2019

LGTM

@alex-lairan alex-lairan marked this pull request as ready for review May 16, 2019 13:05
@alex-lairan
Copy link
Owner Author

I disagree, there is the Exception problem, I try to fix it now ! :)

@alex-lairan
Copy link
Owner Author

I made a solution :)

Take a look

@moba1
Copy link
Collaborator

moba1 commented May 16, 2019

🙆‍♂

@alex-lairan alex-lairan merged commit a8a4135 into master May 18, 2019
@moba1 moba1 deleted the feature/add_task branch May 18, 2019 18:37
@alex-lairan alex-lairan mentioned this pull request May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants