Created
October 17, 2015 11:55
-
-
Save antsmartian/702e2e6c73036abdd0f5 to your computer and use it in GitHub Desktop.
Composition In Swift
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 Foundation | |
func getContents(url: String) -> String { | |
var a = url.componentsSeparatedByString(".") | |
var temp = "" | |
for (index, element) in enumerate(a) { | |
temp = "\(temp) \n \(element)"; | |
} | |
return temp | |
} | |
func lines(input: String) -> [String] { | |
return input.componentsSeparatedByCharactersInSet( | |
NSCharacterSet.newlineCharacterSet()) | |
} | |
let linesInURL = { url in count(lines(getContents(url))) } | |
linesInURL("a.n.t.o") | |
infix operator <<< { associativity left } | |
func <<< <A, B, C>(f: B -> C, g: A -> B) -> A -> C { | |
return { x in f(g(x)) } | |
} | |
let linesInURL2 = count <<< lines <<< getContents | |
linesInURL2("a.n.t.o") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment