Created
April 4, 2015 11:30
-
-
Save icodesign/7bb72d35110941322b1e to your computer and use it in GitHub Desktop.
SinkType Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
let sink = SinkOf<String> { input in | |
println(input) | |
return | |
} | |
sink.put("Hello") | |
sink.put("World!") | |
func run<T>(array: [T], sink: SinkOf<T>){ | |
for element in array { | |
sink.put(element) | |
} | |
} | |
var sum = 0 | |
run ([1,2,3], SinkOf { sum += $0 }) | |
println(sum) | |
run (["h", "e", "l", "l", "o"], SinkOf { println($0.uppercaseString) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment