Created
August 9, 2014 21:53
-
-
Save k06a/dd0369964b4e6164bad0 to your computer and use it in GitHub Desktop.
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
prefix func !<T>(f: (T)->Bool) -> (T)->Bool | |
{ | |
return { !f($0) } | |
} | |
func &&<T>(f1: (T)->Bool, f2: (T)->Bool) -> (T)->Bool | |
{ | |
return { f1($0) && f2($0) } | |
} | |
func ||<T>(f1: (T)->Bool, f2: (T)->Bool) -> (T)->Bool | |
{ | |
return { f1($0) || f2($0) } | |
} | |
func isIn<T: Comparable>(r: Range<T>) -> (T) -> Bool | |
{ | |
return { (r.startIndex <= $0) && ($0 < r.endIndex) }; | |
} | |
let arr = [1,2,3,4,5,6,7,8] | |
let arr2 = filter(arr, isIn(0...2) || isIn(5...7)) |
Author
k06a
commented
Oct 14, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment