Created
November 3, 2020 01:30
-
-
Save masakih/24138ba35b44cf8732ad19c51703bb26 to your computer and use it in GitHub Desktop.
Collectionから取り出した3つの要素の全組み合わせを列挙するやつ #CodePiece
This file contains hidden or 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
| extension Collection { | |
| func list3() -> [[Element]] where Index == Int { | |
| zip(0..., self).flatMap { (i: Int, e0: Element) -> [[Element]] in | |
| zip((i + 1)..., self[(i + 1)...]).flatMap { (j: Int, e1: Element) -> [[Element]] in | |
| self[(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