Code Explainers

Code explainers tagged #enumerators

ruby
def collatz_lengths
  Enumerator.new do |y|
    n = 1
    loop do

Building infinite sequences with lazy enumerators

lazy-evaluation enumerators infinite-sequences
Intermediate 8 steps
ruby
module LogParser
  class AccessLogStreamer
    SEVERITY_PATTERN = /\b(ERROR|WARN|FATAL)\b/
 

Streaming log lines with a Ruby enumerator

enumerators lazy-iteration regex-matching
Intermediate 6 steps