MCPcopy Create free account
hub / github.com/benbjohnson/immutable / First

Method First

immutable.go:1451–1462  ·  view source on GitHub ↗

First resets the iterator to the first key/value pair.

()

Source from the content-addressed store, hash-verified

1449
1450// First resets the iterator to the first key/value pair.
1451func (itr *MapIterator[K, V]) First() {
1452 // Exit immediately if the map is empty.
1453 if itr.m.root == nil {
1454 itr.depth = -1
1455 return
1456 }
1457
1458 // Initialize the stack to the left most element.
1459 itr.stack[0] = mapIteratorElem[K, V]{node: itr.m.root}
1460 itr.depth = 0
1461 itr.first()
1462}
1463
1464// Next returns the next key/value pair. Returns a nil key when no elements remain.
1465func (itr *MapIterator[K, V]) Next() (key K, value V, ok bool) {

Callers 5

IteratorMethod · 0.45
BenchmarkList_IteratorFunction · 0.45
BenchmarkMap_IteratorFunction · 0.45
TestSortedMap_IteratorFunction · 0.45

Calls 1

firstMethod · 0.95

Tested by 4

BenchmarkList_IteratorFunction · 0.36
BenchmarkMap_IteratorFunction · 0.36
TestSortedMap_IteratorFunction · 0.36