Method: Immutable::Set#select

Defined in:
lib/immutable/_core.rb

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

Return a new Set with all the items for which the block returns true.

Examples:

Immutable::Set["Elephant", "Dog", "Lion"].select { |e| e.size >= 4 }
# => Immutable::Set["Elephant", "Lion"]

Yields:

  • (item)

    Once for each item.

Returns:



2679
2680
2681
2682
2683
# File 'lib/immutable/_core.rb', line 2679

def select
  return enum_for(:select) unless block_given?
  trie = @trie.select { |key, _| yield(key) }
  new_trie(trie)
end