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

New sequenceAll combinator #127

Closed
wants to merge 2 commits into from
Closed

New sequenceAll combinator #127

wants to merge 2 commits into from

Conversation

diogob
Copy link
Contributor

@diogob diogob commented Jan 5, 2024

Use case

This fits a similar use case as the passthrough proposed on #96
It can be used to add validation functions to a pipeline that should abort execution on error but don't necessarly produce a result that we want to pipe to the next callee.

For instance, let's say you want to check the state of a record in the database and send a notification only when the validation function is successful.
In this case the resulting type of the validation function should not be taken into account, since you don't want to write the function for the composition.

With the new combinator something like this could be done:

const isValidInDatabase = composable(id: string) => { ... }
const sendNotification = composable(id: string) => { ... }
const sendNotificationWhenValid = sequenceAll(isValidInDatabase, sendNotification)

It also makes it easier to reuse existing functions just for the sake of their side-effects. On the previous example, let's say you want add a function that records a log of messages sent on the database (and fail to send the message in case the log fails).

I was hoping to merge this before we have the full composable documentation.

TODO

  • Add DomainFunction version of the combinator
  • Add README documentation for DomainFunction.

@diogob diogob changed the base branch from main to tight-composition-types January 5, 2024 21:42
@gustavoguichard
Copy link
Collaborator

@diogob , I'm good with having it but the name doesn't do it for me... hard to tell what it does, especially because we have sequence and all and it has nothing to do with them. WDYT?

Base automatically changed from tight-composition-types to main January 6, 2024 02:00
@diogob
Copy link
Contributor Author

diogob commented Jan 6, 2024

@diogob , I'm good with having it but the name doesn't do it for me... hard to tell what it does, especially because we have sequence and all and it has nothing to do with them. WDYT?

I actually derived the name from both, since it takes the typing of all but most of the implementation from sequence. You could say that this is a serial version of the all combinator.

Other possible names along these lines would be:

  • allInSequence
  • allInSeries
  • serialAll

diogob and others added 2 commits February 14, 2024 09:59
…n sequence passing the same input parameters to all of them
Co-authored-by: Guga Guichard <gustavoguichard@gmail.com>
@gustavoguichard
Copy link
Collaborator

tap?

@diogob diogob closed this May 17, 2024
@gustavoguichard gustavoguichard deleted the sequence-all branch May 18, 2024 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants