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

Reimplement Maybe monad wihtout RightBiased and LeftBiased #6

Merged
merged 1 commit into from
Apr 22, 2019

Conversation

moba1
Copy link
Collaborator

@moba1 moba1 commented Apr 21, 2019

  • reimplement these methods:

    • #or(a): if self is Just, return self. but self is Nothing, return Just.new(a)
      • ex Monads::Maybe.return(1).or(Monads::Maybe.return(2)) == Monads::Maybe.return(1)
    • #value_or(a): if self is Just, return Just#value!. self is Nothing, return a
      • ex: Monads::Maybe.return(1).value_or(4) == 1
  • add following method:

    • #map_or(a, &block): if self is Just, return Just#value! applied &block. self is Nothing, return a
      • ex: Monads::Maybe.return(3).map_or(1) {|x| x + 1} == 4
  • add Monad(T) and Functor(T) and Module. Maybe implements these modules.

  • replace these methods:

    • #fmap
      • ex: Monads::Maybe.return(1).fmap {|x| x * 2} == Monads::Maybe.return(2)
    • #bind
      • ex: Monads::Maybe.return(1).bind {|x| Monads::Maybe.return(x.to_s)} == Monads::Maybe.return("1")

@moba1 moba1 requested a review from alex-lairan April 21, 2019 17:12
Copy link
Owner

@alex-lairan alex-lairan left a 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.

src/monads/maybe.cr Outdated Show resolved Hide resolved
src/monads/maybe.cr Outdated Show resolved Hide resolved
src/monads/monad.cr Outdated Show resolved Hide resolved
src/monads/monad.cr Outdated Show resolved Hide resolved
src/monads/functor.cr Outdated Show resolved Hide resolved
src/monads/functor.cr Outdated Show resolved Hide resolved
src/monads/maybe.cr Show resolved Hide resolved
@moba1
Copy link
Collaborator Author

moba1 commented Apr 22, 2019

I pushed wrong author, hence, I repushed.

@moba1
Copy link
Collaborator Author

moba1 commented Apr 22, 2019

Removed wrong commiter from history

@moba1
Copy link
Collaborator Author

moba1 commented Apr 22, 2019

Organize commit

@moba1 moba1 changed the title replace old API Reimplement Maybe monad wihtout RightBiased and LeftBiased Apr 22, 2019
@moba1
Copy link
Collaborator Author

moba1 commented Apr 22, 2019

@alex-lairan All the pointed out parts have been fixed.
please check.

Copy link
Owner

@alex-lairan alex-lairan left a 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

spec/monads_spec.cr Show resolved Hide resolved
src/monads/monad.cr Show resolved Hide resolved
@moba1
Copy link
Collaborator Author

moba1 commented Apr 22, 2019

Do you have anything else you want to point out?

@alex-lairan
Copy link
Owner

I don't think so.

I will implement a CI to simplify the review process.

@moba1
Copy link
Collaborator Author

moba1 commented Apr 22, 2019

For now, should I merge?

@alex-lairan
Copy link
Owner

Yes, let's go

@alex-lairan alex-lairan merged commit 2d958c0 into master Apr 22, 2019
@moba1 moba1 deleted the fix/replace-old-api branch April 22, 2019 14:38
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.

2 participants