module Roadie::Rails::Utils

def combine_callable(first, second)

```
combine_callable(nil, nil).nil? # => true
combine_callable(-> { 1 }, nil).call # => 1
combine_callable(-> { 1 }, -> { 2 }).call # => 2
```ruby

callable.
The result from the second one will be the result of the combined

just return the other.
Return a callable that will call both inputs. If either is nil, then
def combine_callable(first, second)
  combine_nilable(first, second) do |a, b|
    lambda do |*args|
      a.call(*args)
      b.call(*args)
    end
  end
end

def combine_hash(first, second)

Returns nil if both are nil.
Combine two hashes, or return the non-nil hash if either is nil.
def combine_hash(first, second)
  combine_nilable(first, second) do |a, b|
    a.merge(b)
  end
end

def combine_nilable(first, second)

```
combine_nilable(7, 5) { |a, b| a+b } # => 12
combine_nilable(nil, nil) { |a, b| a+b } # => nil
combine_nilable(7, nil) { |a, b| a+b } # => 7
combine_nilable(nil, 5) { |a, b| a+b } # => 5
```ruby

the result from the block.
Discard the nil value. If neither is nil, then yield both and return
def combine_nilable(first, second)
  if first && second
    yield first, second
  else
    first || second
  end
end

def combine_providers(first, second)

the non-nil value instead.
Combine two Provider ducks into a ProviderList. If either is nil, pick
def combine_providers(first, second)
  combine_nilable(first, second) do |a, b|
    ProviderList.new(a.to_a + Array.wrap(b))
  end
end