Method: Immutable::SortedSet#select

Defined in:
lib/immutable/sorted_set.rb

#select {|item| ... } ⇒ SortedSet Also known as: find_all, keep_if

Return a new SortedSet containing all elements for which the given block returns true.

Examples:

Immutable::SortedSet["Bird", "Cow", "Elephant"].select { |e| e.size >= 4 }
# => Immutable::SortedSet["Bird", "Elephant"]

Yields:

  • (item)

    Once for each item.

Returns:



451
452
453
454
455
456
# File 'lib/immutable/sorted_set.rb', line 451

def select
  return enum_for(:select) unless block_given?
  items_to_delete = []
  each { |item| items_to_delete << item unless yield(item) }
  derive_new_sorted_set(@node.bulk_delete(items_to_delete))
end