Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composite#call should take a variable number of arguments #5

Open
robhanlon22 opened this issue Sep 14, 2020 · 1 comment
Open

Composite#call should take a variable number of arguments #5

robhanlon22 opened this issue Sep 14, 2020 · 1 comment

Comments

@robhanlon22
Copy link
Member

Take this example:

# example.rb

require "dry/transformer"

module F
  extend Dry::Transformer::Registry

  def self.constantly(n)
    n
  end

  def self.square(n)
    n ** 2
  end
end

def F(*args)
  F[*args]
end

f = F(:constantly, 5) >> F(:square)
f.call
❯ ruby example.rb
Traceback (most recent call last):
	1: from example.rb:20:in `<main>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/dry-transformer-0.1.1/lib/dry/transformer/composite.rb:32:in `call': wrong number of arguments (given 0, expected 1) (ArgumentError)

Since all arguments have been applied, f.call should not require any arguments. However, Composite#call always requires one argument: https://github.com/dry-rb/dry-transformer/blob/master/lib/dry/transformer/composite.rb#L32 A simple fix would just to make Composite#call take a variable number of arguments, so that the first function in the chain can be called with as many arguments as it needs.

@flash-gordon
Copy link
Member

Do keep in mind *args is an extra allocation, so this potential fix would slow all other cases somewhat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants