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.1 lib/eco/language/curry.rb
eco-helpers-3.0.0 lib/eco/language/curry.rb
eco-helpers-2.7.25 lib/eco/language/curry.rb
eco-helpers-2.7.24 lib/eco/language/curry.rb
eco-helpers-2.7.23 lib/eco/language/curry.rb
eco-helpers-2.7.22 lib/eco/language/curry.rb
eco-helpers-2.7.21 lib/eco/language/curry.rb
eco-helpers-2.7.20 lib/eco/language/curry.rb
eco-helpers-2.7.19 lib/eco/language/curry.rb
eco-helpers-2.7.18 lib/eco/language/curry.rb
eco-helpers-2.7.17 lib/eco/language/curry.rb
eco-helpers-2.7.16 lib/eco/language/curry.rb
eco-helpers-2.7.15 lib/eco/language/curry.rb
eco-helpers-2.7.14 lib/eco/language/curry.rb
eco-helpers-2.7.13 lib/eco/language/curry.rb
eco-helpers-2.7.12 lib/eco/language/curry.rb
eco-helpers-2.7.4 lib/eco/language/curry.rb
eco-helpers-2.7.2 lib/eco/language/curry.rb
eco-helpers-2.7.1 lib/eco/language/curry.rb
eco-helpers-2.7.0 lib/eco/language/curry.rb