[dry-monads] ArgumentError: missing keyword: :items

Describe the bug

ArgumentError:
  missing keyword: :items
# ./app/services/elements/save.rb:11:in `block in call'
# */gems/ruby-3.1.3/gems/dry-monads-1.6.0/lib/dry/monads/right_biased.rb:52:in `bind'
# ./app/services/elements/save.rb:11:in `call'

To Reproduce

class GetDetails
  include Dry::Monads::Result::Mixin

  def call(element)
    elements = [element]
    elements_count = elements.count

    Success(elements:, elements_count:)
  end
end

GetDetails.new.call(1).bind do |elements:, **_|
  p elements
end

Expected behavior

bind has an elements variable

My environment

  • Affects my production application: NO
  • Ruby version: 3.1.3
  • OS: Ubuntu 22.04.1

It’s not specific to dry-monads, ruby is now strict about seq/keyword params. dry-monads pass values as ordinary parameters, they cannot be automatically converted to keywords. It broke use cases like yours but it was a required step to clean up the mess created by mixing keywords and sequential parameters.

You can use pattern matching instead:

GetDetails.new.call(1).bind do |v|
  v => { elements: }
end
1 Like