Skip to content

Instantly share code, notes, and snippets.

@k06a
Created August 9, 2014 21:53
Show Gist options
  • Save k06a/dd0369964b4e6164bad0 to your computer and use it in GitHub Desktop.
Save k06a/dd0369964b4e6164bad0 to your computer and use it in GitHub Desktop.
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))
@k06a
Copy link
Author

k06a commented Oct 14, 2014

if (isIn(0...2) || isIn(5...7))(value) {
    // …
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment