-
Notifications
You must be signed in to change notification settings - Fork 100
Open
Description
Proc#compose raises an error when it shouldn't. The following two lambdas can compose:
make_twin = -> n { return n, n }
take_twin = -> n, m { puts n; puts m }
twin_comp = -> n { take_twin[*make_twin[n]] }
twin_comp[2]
2
2
=> nilBut with Proc#compose, it raises an ArgumentError:
take_twin.compose(make_twin)
ArgumentError: arity count mismatchOne solution is to wrap the inner call in a begin:
class Proc
def compose(g)
lambda do |*a|
begin
self[ *g[*a] ]
rescue ArgumentError => e
puts "#{e.class}: #{e.message}" # or whatever message is appropriate
puts e.backtrace
end
end
end
endThere's not really a way to check a proc's return arity at runtime, since it can return in more than one way.
Metadata
Metadata
Assignees
Labels
No labels