Skip to content

1.5.0: Closeable pulls, readHandle, foldLeft and toGenerator - #11

Merged
MarcelloDuarte merged 3 commits into
mainfrom
developing-1.5.0
Oct 15, 2026
Merged

MarcelloDuarte merged 3 commits into
mainfrom
developing-1.5.0

Conversation

@MarcelloDuarte

Copy link
Copy Markdown
Contributor

Builds on #10 (1.4.2); merge that first and this diff reduces to the 1.5.0 commit.

Added

  • Closeable: a pull that holds a handle is closed exactly once by the compile loop, when the stream ends, when take or takeWhile halts it early, or when an effect throws. Read, HttpRequest, ResourcePull, ResourceObjectPull, ResourcePullConcat and PDOPull implement it; PDOPull::close() calls closeCursor(), which frees a MySQL connection after an unbuffered result set is cut short. After close() a source yields EOF.
  • Functions\io\readHandle(IO $open, int $chunk = 65536): Stream, a thin front over the new OpenedRead resource: the IO runs on the first pull, the handle is closed at EOF and through Closeable. An IO that does not open a stream resource is refused.
  • foldLeft($initial)($f) on a stream, partially applied like ImmList, returning IO<B>; compile()->fold($initial, $f) on the compiler. The fold runs on the lazy loop, one element at a time.
  • compile()->toGenerator(): a Generator for consumers outside the IO discipline. Effects run as the consumer iterates, and the source is closed when the generator finishes or is abandoned.
  • The compile loop is now one private generator with the finally that closes; drain, toList, toArray, fold and toGenerator all iterate it.

Behaviour change, for the release note

Read closes its file handle at end of stream instead of when the last reference goes away. The only observable difference is when the descriptor is released; a pull after close yields EOF, as a second read did before.

Compilable gained fold() and toGenerator(), so a custom Pull outside the family that does not use the shared CompileOps has to add them.

Specs

CloseableSpec, ReadHandleSpec, FoldSpec, ToGeneratorSpec; 190 tests.

@MarcelloDuarte
MarcelloDuarte merged commit 4523119 into main Oct 15, 2026
12 checks passed
@MarcelloDuarte
MarcelloDuarte deleted the developing-1.5.0 branch October 15, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant