Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephan Mantler stephanmantler

View GitHub Profile
@stephanmantler
stephanmantler / fizzbuzz.swift
Created Sep 19, 2020
Functional Swift FizzBuzz
View fizzbuzz.swift
extension Array where Element == Int {
func fizzBuzz() -> [String] {
return self.map(evalBuilder(pickers: [fibui(3, "Fizz"), fibui(5, "Buzz"), fibui(7, "Humm")]))
}
private func fibui(_ mult: Int, _ out: String) -> ((Int)->String?) {
return { (number: Int) in number.isMultiple(of: mult) ? out : nil }
}
private func evalBuilder(pickers:[(Int)->String?]) -> ((Int)->String) {
You can’t perform that action at this time.