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

Extracting primitives inspired by ATMP #119

Merged
merged 41 commits into from
Nov 29, 2023
Merged

Extracting primitives inspired by ATMP #119

merged 41 commits into from
Nov 29, 2023

Conversation

diogob
Copy link
Contributor

@diogob diogob commented Nov 7, 2023

The goal here is to have primitives that don't need parsers and yet compose and handle errors in a similar way as domain functions do.

Unfortunately this won't provide true type safety on compositions, since these composable primitives will work with any Composable function types.

However there are a few good use cases:

  • To define functions that could act as type-safe interfaces to domain functions by calling a toComposable with a fixed type on an already existing DF.
  • To create a function with error handling that does not parsers but could potentially be used in DF compositions by calling a fromComposable and giving the parsers.
  • To bravely compose async functions without any sort of type-safety but without having to juggle awaits and exceptions.

Inspired by the atmp library.

This PR is aiming at a "soft launch" where we can release a new version of the lib without breaking changes or any change in documentation.

TODO

  • ensure trace will handle traceFn errors gracefully
  • Implement conversion from ATMP -> DF (fromComposable)
  • Implement conversion from DF -> ATMP (toComposable)
  • Rename ATMP module (renamed to composable)
  • Ensure Composable compositions are type-safe (at least when all generics have been passed)

Comment on lines 40 to 65
const [first, ...rest] = fns.map((df) =>
atmp(() => fromSuccess(df)(input, environment)),
)
return dfResultFromAtmp(A.all(first, ...rest))()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the destructuring here?
Wouldn't this work?

Suggested change
const [first, ...rest] = fns.map((df) =>
atmp(() => fromSuccess(df)(input, environment)),
)
return dfResultFromAtmp(A.all(first, ...rest))()
const results = fns.map((df) =>
atmp(() => fromSuccess(df)(input, environment)),
)
return dfResultFromAtmp(A.all(results))()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not type check. I just assumed that the type was like that by design, but I could be wrong.

@diogob diogob force-pushed the take-5 branch 3 times, most recently from 61476dc to 71d9dbf Compare November 8, 2023 15:58
@diogob diogob force-pushed the take-5 branch 2 times, most recently from 1a223fd to 0469490 Compare November 16, 2023 15:12
@diogob diogob marked this pull request as ready for review November 16, 2023 16:31
Copy link
Collaborator

@gustavoguichard gustavoguichard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
I'd add a cf alias to composable given we already have mdf and its success 🤭

@diogob
Copy link
Contributor Author

diogob commented Nov 29, 2023

I'm merging this one since it is backwards compatible and it seems that we are quite comfortable now with the direction it is taking. I'll hold the merge on the primitives type-safety for now.
We also don't need to make any releases for now so we have some change to let ideas percolate with the current main branch code.

@diogob diogob merged commit ae6169e into main Nov 29, 2023
2 checks passed
@diogob diogob deleted the take-5 branch November 29, 2023 17:14
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.

2 participants