diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-31 16:59:18 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-31 16:59:18 +0800 |
commit | 655b6b211ae6df0186abd740f248939f7ddeaec1 (patch) | |
tree | ec5cdbbc52222f62c8fbb0bcf2a1aa7a9f6eb8b6 /iter.go | |
parent | Correct table headers in MR indices (diff) | |
download | forge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.gz forge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.zst forge-655b6b211ae6df0186abd740f248939f7ddeaec1.zip |
Add descriptive comments to most Go functions
Diffstat (limited to 'iter.go')
-rw-r--r-- | iter.go | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> + +package main + +import "iter" + +// iterSeqLimit returns an iterator equivalent to the supplied one, but stops +// after n iterations. +func iterSeqLimit[T any](s iter.Seq[T], n uint) iter.Seq[T] { + return func(yield func(T) bool) { + var iterations uint + for v := range s { + if iterations > n-1 { + return + } + if !yield(v) { + return + } + iterations++ + } + } +} |