Coder Social home page Coder Social logo

ribimaybe's People

Contributors

filib avatar mcfilib avatar raganwald avatar unsymbol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

bobjflong

ribimaybe's Issues

Alias #inspect to #to_s

[~]
% ruby --version
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin13.0.0]
[~]
% irb
irb(main):001:0> require 'ribimaybe'
=> true
irb(main):002:0> include Ribimaybe::Maybe
=> Object
irb(main):003:0> Maybe(nil)
=> Ribimaybe::Maybe::Nothing
irb(main):004:0> puts Maybe(nil)
Nothing
=> nil
irb(main):005:0>

Prove Maybe is an Applicative Functor

pure id <*> v = v                            -- Identity
pure (.) <*> u <*> v <*> w = u <*> (v <*> w) -- Composition
pure f <*> pure x = pure (f x)               -- Homomorphism
u <*> pure y = pure ($ y) <*> u              -- Interchange

And the Functor instance should satisfy the following law:

fmap f x = pure f <*> x                      -- Fmap

Consider renaming rturn

It's unfortunate that return is a reserved keyword in Ruby and I worry that the ergonomics of #rturn are unsatisfactory.

Return type for `Just#bind` insufficiently general

sorry for the terminology, I'm not familiar with the Contracts library

Just(1).bind{|x|
  Nothing.bind{|y|
    rturn(x+y)}}

should return Nothing. Instead:

Contract violation for return value: (ContractError)
    Expected: Ribimaybe::Maybe::Just,
    Actual: Ribimaybe::Maybe::Nothing
    Value guarded in: Ribimaybe::Maybe::Just::bind
    With Contract: Proc => Ribimaybe::Maybe::Just

Prove Maybe is a Monad

m >>= return     =  m                        -- right unit
return x >>= f   =  f x                      -- left unit

(m >>= f) >>= g  =  m >>= (\x -> f x >>= g)  -- associativity

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.