Sha256: d011258e43794513f9f3f25b57edbe018d67f21abe939a37a91bcc4c7da911f7

Contents?: true

Size: 843 Bytes

Versions: 236

Compression:

Stored size: 843 Bytes

Contents

module Eco
  module Language

    def required_parameters(method)
      method.parameters.select { |type, _| type == :req || :keyreq}
    end

    def required_parameters?(method)
      required_parameters(method).length > 0
    end

    def curry(method)
      -> (*args, **kargs) {
        required  = method.parameters.select { |type, _| type == :req }
        krequired = method.parameters.select { |type, _| type == :keyreq }
        all_args = (required.length <= args.length)
        all_keys = krequired.all? { |_, name| kargs.has_key?(name) }
        if all_args && all_keys
          final_args = (args + kargs.map {|k,v| {k => v} })
          method.call(*final_args)
        else
          -> (*args_, **kargs_) { curry(method)[*args, *args_, **kargs, **kargs_] }
        end
      }
    end

  end
end

Version data entries

236 entries across 236 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/language/curry.rb
eco-helpers-3.0.20 lib/eco/language/curry.rb
eco-helpers-3.0.19 lib/eco/language/curry.rb
eco-helpers-3.0.18 lib/eco/language/curry.rb
eco-helpers-3.0.17 lib/eco/language/curry.rb
eco-helpers-3.0.16 lib/eco/language/curry.rb
eco-helpers-3.0.15 lib/eco/language/curry.rb
eco-helpers-3.0.14 lib/eco/language/curry.rb
eco-helpers-3.0.13 lib/eco/language/curry.rb
eco-helpers-3.0.12 lib/eco/language/curry.rb
eco-helpers-3.0.11 lib/eco/language/curry.rb
eco-helpers-3.0.10 lib/eco/language/curry.rb
eco-helpers-3.0.9 lib/eco/language/curry.rb
eco-helpers-3.0.8 lib/eco/language/curry.rb
eco-helpers-3.0.7 lib/eco/language/curry.rb
eco-helpers-3.0.6 lib/eco/language/curry.rb
eco-helpers-3.0.5 lib/eco/language/curry.rb
eco-helpers-3.0.4 lib/eco/language/curry.rb
eco-helpers-3.0.3 lib/eco/language/curry.rb
eco-helpers-3.0.2 lib/eco/language/curry.rb