Skip to content

Instantly share code, notes, and snippets.

@LeoValentim
Created August 13, 2019 14:38
Show Gist options
  • Save LeoValentim/0426ce68265ddbe352062c71979a551f to your computer and use it in GitHub Desktop.
Save LeoValentim/0426ce68265ddbe352062c71979a551f to your computer and use it in GitHub Desktop.
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