Feature #8421

add Enumerable#find_map and Enumerable#find_all_map

Added by Hans Mackowiak 11 months ago. Updated 11 months ago.

[ruby-core:55045]
Status:Feedback
Priority:Normal
Assignee:-
Category:-
Target version:-

Description

currently if you have an Enumerable and you want to return the return value of #find you need eigther:
(o = enum.find(block) && block.call(o)) || nil
or
enum.inject(nil) {|ret,el| ret || block.call(el)}

neigher of them may be better than an directly maked method

same for #findallmap
enum.lazy.map(&:block).find_all{|el| el}

it may work but it is not so good

History

#1 Updated by Yukihiro Matsumoto 11 months ago

  • Status changed from Open to Feedback

Could you tell me a concrete use-case of your findmap and findallmap?
Usually a block for find/find
all gives boolean so that I personally have never wanted the return value from it.

Matz.

Also available in: Atom PDF