Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sequence::sink() #32

Merged
merged 1 commit into from
Dec 1, 2024
Merged

Add Sequence::sink() #32

merged 1 commit into from
Dec 1, 2024

Conversation

Baptouuuu
Copy link
Member

Request

In many Innmind packages the pattern of reducing a Sequence with a carried value of Maybe or Either is used to iteratively operate IO operations that may fail and return this potential failure. (An example is the creation of a temporary file in innmind/operating-system).

The current implementation brings 2 problems:

  • the typing of this reducing is annoying because Psalm have a hard time keeping track of types inside the Maybe/Either
  • if the reducing fails it keeps iterating over the source Sequence even though it's not used

Solution

This PR adds a Sequence::sink()->until() that is the same as Sequence::reduce() except it uses the continuation pattern to know when to stop reducing.

On top of that, ->sink()->maybe() and ->sink()->either() are added as shortcuts to imply the continuation from the values contained in the Maybe/Either.

This should help simplify other packages and their performance.

@Baptouuuu Baptouuuu added the enhancement New feature or request label Dec 1, 2024
@Baptouuuu Baptouuuu self-assigned this Dec 1, 2024
@Baptouuuu Baptouuuu merged commit e0d1991 into develop Dec 1, 2024
21 checks passed
@Baptouuuu Baptouuuu deleted the sequence-sink branch December 1, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant