From 0a6bcc3c6828b490924490a42104f83f126e231d Mon Sep 17 00:00:00 2001 From: Oliver Atkinson Date: Fri, 6 Nov 2020 15:25:34 +0000 Subject: [PATCH] compute the stride only when the next element is requested --- Sources/Algorithms/Stride.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/Algorithms/Stride.swift b/Sources/Algorithms/Stride.swift index 19ca012..4f4ef53 100644 --- a/Sources/Algorithms/Stride.swift +++ b/Sources/Algorithms/Stride.swift @@ -56,12 +56,15 @@ extension Stride: Sequence { var iterator: Base.Iterator let stride: Int + var striding: Bool = false public mutating func next() -> Base.Element? { - defer { - for _ in 0..<(stride - 1) { - guard iterator.next() != nil else { break } - } + guard striding else { + striding = true + return iterator.next() + } + for _ in 0..