Skip to content

Instantly share code, notes, and snippets.

@mickmaccallum
Last active October 20, 2015 13:44
Show Gist options
  • Select an option

  • Save mickmaccallum/2cfefd3f610a703cb59d to your computer and use it in GitHub Desktop.

Select an option

Save mickmaccallum/2cfefd3f610a703cb59d to your computer and use it in GitHub Desktop.

Revisions

  1. @0x7FFFFFFF 0x7FFFFFFF revised this gist Oct 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fizzBuzzGenerator.swift
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ struct FizzBuzzGenerator: SequenceType {
    }
    }

    let fizzBuzzSequence = lazy(FizzBuzzGenerator(bounds: 1...100))
    let fizzBuzzSequence = FizzBuzzGenerator(bounds: 1...100).lazy
    for x in fizzBuzzSequence {
    print(x)
    }
  2. @0x7FFFFFFF 0x7FFFFFFF revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fizzBuzzGenerator.swift
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    struct FizzBuzzGenerator: SequenceType {
    private var bounds: Range<Int>
    private let bounds: Range<Int>

    func generate() -> AnyGenerator<String> {
    var current = bounds.startIndex
  3. @0x7FFFFFFF 0x7FFFFFFF revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fizzBuzzGenerator.swift
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ struct FizzBuzzGenerator: SequenceType {
    }
    }

    let fizzBuzzSequence = FizzBuzzGenerator(bounds: 1...100)
    let fizzBuzzSequence = lazy(FizzBuzzGenerator(bounds: 1...100))
    for x in fizzBuzzSequence {
    print(x)
    }
  4. @0x7FFFFFFF 0x7FFFFFFF revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fizzBuzzGenerator.swift
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ struct FizzBuzzGenerator: SequenceType {
    }
    }

    let fizzBuzzSequence = FizzBuzzGenerator(bounds: 1...1000)
    let fizzBuzzSequence = FizzBuzzGenerator(bounds: 1...100)
    for x in fizzBuzzSequence {
    print(x)
    }
  5. @0x7FFFFFFF 0x7FFFFFFF created this gist Jul 31, 2015.
    33 changes: 33 additions & 0 deletions fizzBuzzGenerator.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    struct FizzBuzzGenerator: SequenceType {
    private var bounds: Range<Int>

    func generate() -> AnyGenerator<String> {
    var current = bounds.startIndex

    return anyGenerator {
    guard current < self.bounds.endIndex else {
    return nil
    }

    let output: String
    switch (current % 3, current % 5) {
    case (0, 0):
    output = "FizzBuzz"
    case (0, _):
    output = "Fizz"
    case (_, 0):
    output = "Buzz"
    default:
    output = String(current)
    }

    current++
    return output
    }
    }
    }

    let fizzBuzzSequence = FizzBuzzGenerator(bounds: 1...1000)
    for x in fizzBuzzSequence {
    print(x)
    }