Last active
March 7, 2022 21:47
-
-
Save justinmeiners/ab87e47e5f6fd1451d29d5bb29b6beaf to your computer and use it in GitHub Desktop.
Revisions
-
justinmeiners revised this gist
Feb 25, 2022 . No changes.There are no files selected for viewing
-
justinmeiners revised this gist
Feb 25, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ enum SequenceMultiplicity<S: Sequence> { extension Sequence { func multiplicity(where predicate: (Element) -> Bool) -> SequenceMultiplicity<Self> { var it = makeIterator() while let x = it.next() { if predicate(x) { while let y = it.next() { -
justinmeiners revised this gist
Feb 25, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,13 +6,13 @@ enum CollectionMultiplicity<C: Collection> { extension Collection { func indexedMultiplicity(where predicate: (Element) -> Bool) -> CollectionMultiplicity<Self> { guard let i = firstIndex(where: predicate) else { return .none } guard let j = suffix(from: index(after: i)).firstIndex(where: predicate) else { return .one(first: i) } return .many(first: i, second: j) } } -
justinmeiners revised this gist
Feb 25, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ extension Collection { guard let x = firstIndex(where: predicate) else { return .none } guard let y = suffix(from: index(after: x)).firstIndex(where: predicate) else { return .one(first: x) } return .many(first: x, second: y) -
justinmeiners revised this gist
Feb 25, 2022 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,14 +6,13 @@ enum CollectionMultiplicity<C: Collection> { extension Collection { func indexedMultiplicity(where predicate: (Element) -> Bool) -> CollectionMultiplicity<Self> { guard let x = firstIndex(where: predicate) else { return .none } guard let y = suffix(from: index(after: first)).firstIndex(where: predicate) else { return .one(first: x) } return .many(first: x, second: y) } } @@ -26,7 +25,6 @@ enum SequenceMultiplicity<S: Sequence> { extension Sequence { func multiplicity(where predicate: (Element) -> Bool) -> SequenceMultiplicity<Self> { var it = self.makeIterator() while let x = it.next() { if predicate(x) { while let y = it.next() { -
justinmeiners created this gist
Feb 25, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ enum CollectionMultiplicity<C: Collection> { case none case one(first: C.Index) case many(first: C.Index, second: C.Index) } extension Collection { func indexedMultiplicity(where predicate: (Element) -> Bool) -> CollectionMultiplicity<Self> { guard let first = firstIndex(where: predicate) else { return .none } guard let second = suffix(from: index(after: first)).firstIndex(where: predicate) else { return .one(first: first) } return .many(first: first, second: second) } } enum SequenceMultiplicity<S: Sequence> { case none case one(first: S.Element) case many(first: S.Element, second: S.Element) } extension Sequence { func multiplicity(where predicate: (Element) -> Bool) -> SequenceMultiplicity<Self> { var it = self.makeIterator() while let x = it.next() { if predicate(x) { while let y = it.next() { if predicate(y) { return .many(first: x, second: y) } } return .one(first: x) } } return .none } }