forked from ChartsOrg/Charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove swift-algorithms package in favor of manully importing needed …
…functions
- Loading branch information
Showing
15 changed files
with
178 additions
and
79 deletions.
There are no files selected for viewing
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
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
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
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
2 changes: 1 addition & 1 deletion
2
ChartsDemo-iOS/ChartsDemo-iOS.xcodeproj/xcshareddata/xcschemes/ChartsDemo-iOS-Swift.xcscheme
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
2 changes: 1 addition & 1 deletion
2
ChartsDemo-iOS/ChartsDemo-iOS.xcodeproj/xcshareddata/xcschemes/ChartsDemo-iOS.xcscheme
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
2 changes: 1 addition & 1 deletion
2
ChartsDemo-macOS/ChartsDemo-macOS.xcodeproj/xcshareddata/xcschemes/ChartsDemo-macOS.xcscheme
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift Algorithms open source project | ||
// | ||
// Copyright (c) 2020 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// A collection wrapper that iterates over the indices and elements of a | ||
/// collection together. | ||
struct IndexedCollection<Base: Collection> { | ||
/// The base collection. | ||
let base: Base | ||
|
||
init(base: Base) { | ||
self.base = base | ||
} | ||
} | ||
|
||
extension IndexedCollection: Collection { | ||
/// The element type for an `IndexedCollection` collection. | ||
typealias Element = (index: Base.Index, element: Base.Element) | ||
|
||
var startIndex: Base.Index { | ||
base.startIndex | ||
} | ||
|
||
var endIndex: Base.Index { | ||
base.endIndex | ||
} | ||
|
||
subscript(position: Base.Index) -> Element { | ||
(index: position, element: base[position]) | ||
} | ||
|
||
func index(after i: Base.Index) -> Base.Index { | ||
base.index(after: i) | ||
} | ||
|
||
func index(_ i: Base.Index, offsetBy distance: Int) -> Base.Index { | ||
base.index(i, offsetBy: distance) | ||
} | ||
|
||
func index( | ||
_ i: Base.Index, | ||
offsetBy distance: Int, | ||
limitedBy limit: Base.Index | ||
) -> Base.Index? { | ||
base.index(i, offsetBy: distance, limitedBy: limit) | ||
} | ||
|
||
func distance(from start: Base.Index, to end: Base.Index) -> Int { | ||
base.distance(from: start, to: end) | ||
} | ||
|
||
var indices: Base.Indices { | ||
base.indices | ||
} | ||
} | ||
|
||
//extension IndexedCollection: BidirectionalCollection | ||
// where Base: BidirectionalCollection | ||
//{ | ||
// func index(before i: Base.Index) -> Base.Index { | ||
// base.index(before: i) | ||
// } | ||
//} | ||
// | ||
//extension IndexedCollection: RandomAccessCollection | ||
// where Base: RandomAccessCollection {} | ||
// | ||
//extension IndexedCollection: LazySequenceProtocol, LazyCollectionProtocol | ||
// where Base: LazySequenceProtocol {} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// indexed() | ||
//===----------------------------------------------------------------------===// | ||
|
||
extension Collection { | ||
/// Returns a collection of pairs *(i, x)*, where *i* represents an index of | ||
/// the collection, and *x* represents an element. | ||
/// | ||
/// This example iterates over the indices and elements of a set, building an | ||
/// array consisting of indices of names with five or fewer letters. | ||
/// | ||
/// let names: Set = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"] | ||
/// var shorterIndices: [Set<String>.Index] = [] | ||
/// for (i, name) in names.indexed() { | ||
/// if name.count <= 5 { | ||
/// shorterIndices.append(i) | ||
/// } | ||
/// } | ||
/// | ||
/// Returns: A collection of paired indices and elements of this collection. | ||
func indexed() -> IndexedCollection<Self> { | ||
IndexedCollection(base: self) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.