Sha256: c6b5bfcc4cbbcceb4040bb013a5d7b6e68dd1bc460b18b6394be63eecada6489

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 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
      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

1 entries across 1 versions & 1 rubygems

Version Path
funkr-0.0.3 lib/funkr/categories/applicative.rb