Skip to content

Instantly share code, notes, and snippets.

@k06a
Created August 30, 2014 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k06a/39f527164e810ec63d26 to your computer and use it in GitHub Desktop.
Save k06a/39f527164e810ec63d26 to your computer and use it in GitHub Desktop.
Swift implementation of Haskell elem function
func elem<T: Equatable>(item: @autoclosure ()->T) -> (@autoclosure ()->[T]) -> Bool {
return { (arr: @autoclosure ()->[T]) in find(arr(), item()) != nil }
}
let found = elem (2) ([1,2,3]) // Hope to avoid braces in future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment