Given an Enumerable, you can detect a value that matches a condition. But what if you want the result of the evaluation? You can now use _Enumerable##detect_value _from the enumerable-detect-value gem.
Consider an example where you have an expensive Geocoder.search operation and a list of addresses, two of which are fake. The function returns nil for a fake address. We would like to find the geo-location of the first real address.
We would now have to call Geocoder.search on first_real_address twice.
Instead, using detect_value you can return the geo-location of the first real address.
The implementation for detect_value is straightforward.
I don’t think this can this be done with the current Ruby standard library without introducing a temporary variable, and Enumerable##Lazy won’t help_._