Cats.rb

Cats.rb is a collection of Category Theory libs for Ruby. You'll find it very handy if you familiar with Haskell or scalaz/cats

CircleCI Document Coverage Status License

:joy_cat: :arrow_right: :smirk_cat:
:arrow_down: :arrow_lower_right: :arrow_down:
:scream_cat: :arrow_right: :heart_eyes_cat:

ADT

data.either

Gem Gem Document

install

gem install data.either

How to use

require 'data.either'
Right.new(1).flat_map do |x| 
  if x < 1
    Left.new('meh')
  else
    Right.new(x+1)
  end
end
# => #<Right value=2>

Right.new(1) >> Left.new('oops') >> Right.new(1) # => #<Left value=oops>

more detail on Document

data.maybe

Gem Gem

install

gem install data.maybe

How to use

require 'data.maybe'
Just.new(1).flat_map do |x| 
  if x < 1
    Nothing
  else
    Just.new(x+1)
  end
end
# => #<Just 2>

Maybe.new(1) >> Nothing >> Maybe.new(2) # => #<Nothing>

WIP

control.monad.free

install

gem install control.monad.free

How to use

Roll.new(Just.new(Return.new(1))).flat_map { |x| Roll.new(Right.new(Return.new(x + 1))) }
# Roll.new(Just.new(Roll.new(Right.new(Return.new(2)))))

control.exception

to be continue...

  • data.validate