mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
548 B
Swift
21 lines
548 B
Swift
7 years ago
|
//
|
||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
public extension Collection {
|
||
|
|
||
|
/// Returns the element at the specified index iff it is within bounds, otherwise nil.
|
||
5 years ago
|
subscript (safe index: Index) -> Element? {
|
||
7 years ago
|
return indices.contains(index) ? self[index] : nil
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
|
public extension Array {
|
||
5 years ago
|
|
||
7 years ago
|
func chunked(by chunkSize: Int) -> [[Element]] {
|
||
|
return stride(from: 0, to: self.count, by: chunkSize).map {
|
||
|
Array(self[$0..<Swift.min($0 + chunkSize, self.count)])
|
||
|
}
|
||
|
}
|
||
|
}
|