Skip to content

Commit

Permalink
scanner.Err
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldrudell committed Feb 17, 2025
1 parent 193ada7 commit afbe15a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/iter/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ func Example() {
}

// iterate over lines from test.txt
// - the LineReader iterator is allocated on the stack
// - first argument shows iterator allocated on the stack
// - second argument shows providing data to iterator
// - third argument shows receiving error from iterator
// - —
// - stack allocation is faster than heap allocation
// - LineReader is on stack even if NewLineReader is in another module
// - LineReader pointer receiver is more performant
Expand Down Expand Up @@ -56,7 +59,7 @@ type LineReader struct {
func NewLineReader(fieldp *LineReader, filename string, errp *error) (lineReader *LineReader) {
if fieldp != nil {
lineReader = fieldp
osFile = nil
lineReader.osFile = nil
} else {
lineReader = &LineReader{}
}
Expand All @@ -83,7 +86,8 @@ func (r *LineReader) Lines(yield func(line string) (keepGoing bool)) {
return // iteration canceled by break or such
}
}
// reached end of file
err = scanner.Err()
// reached end of file or error
}

// LineReader.Lines is iter.Seq string
Expand Down

0 comments on commit afbe15a

Please sign in to comment.