Possibly remove auto-wrapping of callables
Closed this issue · 1 comments
ianks commented
When creating a pipeline, non-callables are wrapped automatically:
def self.pipe(callable)
if callable.respond_to?(:call)
Pipeline.new([callable])
else
Pipeline.new([->(_) { callable }])
end
end
I'm not sure that the pros outweigh the cons here.
Pros:
- Saves the user from having to wrap argument in a lambda themselves
Cons:
- It can lead to confusing scenarios when typos occurs (fat-thumbing a method as
calll
and wondering why everything is mysteriously broken) - Encourages use of magic behavior. If someone uses a non-callable as an argument, I have to ask myself some questions: a) is the argument a callable? source dive b) if it's not, i will likely have to source dive to see that Pipeline automatically wraps non-callables. IME, it's not obvious that Pipeline should do this for me.
- respond_to? adds a small percentage overhead which many people will pay for and potentially small amount of people will use.
Overall I think it would be wise to remove the respond_to? :call
check in favor of explicitness.
lautis commented
I agree that the pattern is a bit risky and works better when the used version of a method is chosen at compile-time. Happy to remove this if there is a replacement method with a clear name for the wrap + initialise behaviour.