-
Notifications
You must be signed in to change notification settings - Fork 2
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
Reimplement Maybe
monad wihtout RightBiased
and LeftBiased
#6
Conversation
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.
Crystal and Haskell are very differents.
They don't have the same naming convention and not the same logic.
Haskell doesn't have inheritance (composition is key 😆) and he optimise his code in a different way than Crystal.
I think also that ulgy name (in crystal) will not help people to get in monads.
37364c2
to
97bf665
Compare
I pushed wrong author, hence, I repushed. |
87dfe28
to
a3e56ea
Compare
Removed wrong commiter from history |
d8d45b5
to
5cfdc56
Compare
Organize commit |
Maybe
monad wihtout RightBiased
and LeftBiased
@alex-lairan All the pointed out parts have been fixed. |
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.
I prefer this naming :)
2/3 thing's to change and LGTM
Do you have anything else you want to point out? |
I don't think so. I will implement a CI to simplify the review process. |
For now, should I merge? |
Yes, let's go |
reimplement these methods:
#or(a)
: ifself
isJust
, returnself
. butself
isNothing
, returnJust.new(a)
Monads::Maybe.return(1).or(Monads::Maybe.return(2)) == Monads::Maybe.return(1)
#value_or(a)
: ifself
isJust
, returnJust#value!
.self
isNothing
, returna
Monads::Maybe.return(1).value_or(4) == 1
add following method:
#map_or(a, &block)
: ifself
isJust
, returnJust#value!
applied&block
.self
isNothing
, returna
Monads::Maybe.return(3).map_or(1) {|x| x + 1} == 4
add
Monad(T)
andFunctor(T)
and Module.Maybe
implements these modules.replace these methods:
#fmap
Monads::Maybe.return(1).fmap {|x| x * 2} == Monads::Maybe.return(2)
#bind
Monads::Maybe.return(1).bind {|x| Monads::Maybe.return(x.to_s)} == Monads::Maybe.return("1")