Project

General

Profile

Actions

Feature #8421

closed

add Enumerable#find_map and Enumerable#find_all_map

Added by Hanmac (Hans Mackowiak) almost 11 years ago. Updated about 1 month ago.

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

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 #find_all_map
enum.lazy.map(&:block).find_all{|el| el}

it may work but it is not so good

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0