Sha256: b30d2a232e02941bfd2ae1adb8f8891871d7c83e1ff4830d43bab36b8f078ddb

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 KB

Contents

module Funkr
  module Categories
    module Applicative
      
      def apply
        raise "Applicative#apply not implemented"
      end

      module ClassMethods
        def curry_lift_proc(&block)
          self.pure(block.curry)
        end

        def full_lift_proc(&block)
          lambda do |*args|
            args.inject(curry_lift_proc(&block)) do |a,e|
              a.apply(e)
            end
          end
        end

        def lift_with(*args, &block)
          full_lift_proc(&block).call(*args)
        end
      end

      
      def <=>(other)
        proxy_comp(other){|a,b| a <=> b}
      end
       
      def ==(other)
        proxy_comp(other){|a,b| a == b}
      end

      def <(other)
        proxy_comp(other){|a,b| a < b}
      end

      def <=(other)
        proxy_comp(other){|a,b| a <= b}
      end

      def >(other)
        proxy_comp(other){|a,b| a > b}
      end

      def >=(other)
        proxy_comp(other){|a,b| a >= b}
      end


      private

      def proxy_comp(other,&block)
        self.class.
          curry_lift_proc(&block).
          apply(self).apply(other)
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
funkr-0.0.23 lib/funkr/categories/applicative.rb
funkr-0.0.22 lib/funkr/categories/applicative.rb
funkr-0.0.21 lib/funkr/categories/applicative.rb
funkr-0.0.20 lib/funkr/categories/applicative.rb
funkr-0.0.19 lib/funkr/categories/applicative.rb
funkr-0.0.18 lib/funkr/categories/applicative.rb
funkr-0.0.17 lib/funkr/categories/applicative.rb
funkr-0.0.16 lib/funkr/categories/applicative.rb
funkr-0.0.15 lib/funkr/categories/applicative.rb
funkr-0.0.14 lib/funkr/categories/applicative.rb
funkr-0.0.12 lib/funkr/categories/applicative.rb
funkr-0.0.11 lib/funkr/categories/applicative.rb
funkr-0.0.10 lib/funkr/categories/applicative.rb
funkr-0.0.9 lib/funkr/categories/applicative.rb
funkr-0.0.8 lib/funkr/categories/applicative.rb
funkr-0.0.7 lib/funkr/categories/applicative.rb
funkr-0.0.6 lib/funkr/categories/applicative.rb
funkr-0.0.5 lib/funkr/categories/applicative.rb
funkr-0.0.4 lib/funkr/categories/applicative.rb