Created
August 13, 2019 14:38
-
-
Save LeoValentim/0426ce68265ddbe352062c71979a551f to your computer and use it in GitHub Desktop.
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
extension Sequence { | |
/// Limits sequence indexes to a given maximum number | |
/// | |
/// - Parameter max: maximum number of indexes | |
/// - Returns: return limited sequence | |
public func limit(_ max: Int) -> [Element] { | |
return self.enumerated() | |
.filter { $0.offset < max } | |
.map { $0.element } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment