Created
July 2, 2015 03:47
-
-
Save NachoSoto/e4569159c001ab654a72 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
//select ::[a] ->[(a, [a])] | |
//select[] = [] | |
//select(x:xs) = (x, xs) : [(y, x:ys) | (y, ys) <-select xs] | |
func select<T>(input: [T]) -> [(T, [T])] { | |
if (input.isEmpty) { | |
return [] | |
} else { | |
let head = input[0] | |
let rest = Array(input[1..<input.count]) | |
return [(head, rest)] + select(rest).map { ($0, [head] + $1) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment