I like how detect works. If you don't pass a handler, raise an error
^#(John Doe) detect: [:each | each = 'Ramon'] => Error: Object is not in the collection
If you want to handle the error, don't catch it, make another method that takes the handler as an arg so the api is cleaner, so the client doesn't have to catch it.
^#(John Doe) detect: [:each | each = 'Ramon'] ifNone:['']
Then you can return nil via the handler if you like, or just handle the error some other way like returning an empty string, or don't pass a handler and let the exception propagate.
This is exactely what I was thinking about. But, this is not that easy in my case because I'm working on reimplementing Streams.
Look at Stream>>next for example. It returns nil when there is no more element. Should I keep this behavior ? Should I implement Stream>>nextIfNoMore:.
Look at Stream>>next: now. This method returns a collection with the following x elements (x given as a parameter). If there is not enough element, the collection contains the last elements.
Would you think that a new Stream hierarchy should be more coherent and clearer, or do you think it should keep compatibility ?