Method: Immutable::List#span
- Defined in:
- lib/immutable/list.rb
#span {|item| ... } ⇒ Array
Return two ‘List`s, one up to (but not including) the first item for which the block returns nil or false, and another of all the remaining items.
508 509 510 511 512 513 514 |
# File 'lib/immutable/list.rb', line 508 def span(&block) return [self, EmptyList].freeze unless block_given? splitter = Splitter.new(self, block) mutex = Mutex.new [Splitter::Left.new(splitter, splitter.left, mutex), Splitter::Right.new(splitter, mutex)].freeze end |