Method: Immutable::Set#select

Defined in:
lib/immutable/set.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:



195
196
197
198
199
# File 'lib/immutable/set.rb', line 195

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