Skip to content

Instantly share code, notes, and snippets.

@winny-
Created January 26, 2018 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winny-/08bd68320e36157cc14a98a400430278 to your computer and use it in GitHub Desktop.
Save winny-/08bd68320e36157cc14a98a400430278 to your computer and use it in GitHub Desktop.
#lang racket
(require srfi/41)
(define (fizzbuzz-stream)
(let loop ([n 1])
(stream-cons
(match* ((modulo n 3) (modulo n 5))
[(0 0) "FizzBuzz"]
[(0 _) "Fizz"]
[(_ 0) "Buzz"]
[(_ _) (number->string n)])
(loop (add1 n)))))
(module+ test
(require rackunit)
(check-equal? (stream->list (stream-take 15 (fizzbuzz-stream)))
'("1" "2" "Fizz" "4" "Buzz" "Fizz" "7" "8" "Fizz" "Buzz" "11" "Fizz" "13" "14" "FizzBuzz")))
(module+ main
(stream-for-each displayln (stream-take 100 (fizzbuzz-stream))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment