Skip to content

Instantly share code, notes, and snippets.

@masakih
Created November 3, 2020 02:01
Show Gist options
  • Select an option

  • Save masakih/296241d991e619c0e90ede6f4581891e to your computer and use it in GitHub Desktop.

Select an option

Save masakih/296241d991e619c0e90ede6f4581891e to your computer and use it in GitHub Desktop.
Indexへの制約を外したのでStringに直接使える #CodePiece
extension Collection {
func list3() -> [[Element]] {
zip(0..., self).flatMap { (i: Int, e0: Element) -> [[Element]] in
zip((i + 1)..., self[index(startIndex, offsetBy: (i + 1))...]).flatMap { (j: Int, e1: Element) -> [[Element]] in
self[index(startIndex, offsetBy: (j + 1))...].map { (e2: Element) -> [Element] in
[e0, e1, e2]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment