Skip to content

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

@robhanlon22

Description

@robhanlon22

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions