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

Use Do from fp-ts-contrib to reduce nesting #1143

Merged
merged 23 commits into from May 4, 2020
Merged

Conversation

XVincentX
Copy link
Contributor

@XVincentX XVincentX commented May 1, 2020

During my daily Haskell reading I discovered the Do notation that such language has and how it simplifies a lot the dealing with multiple Monads when you have to, yes, chain the things together but you do not want to lose the previous value after a chain.

Such situation is not manageable in fp-ts and we've been doing some hacks (well they're not hacks frankly, it's just the way it should be done) — and so here we are.

After learning about Haskell, I started to look into various alternatives to see if there'd be a way to accumulate the results over time and having better code.

I found what I was looking for in fp-ts-contrib package. I won't go in detail in this code, I think it's self explanatory and you can see how the readability has improved significantly. To understand a little bit more about the feature, point your browser to this article: https://paulgray.net/do-syntax-in-typescript/

I am pretty sure I have covered all the parts in Prism — but I might have missed some we can refactor as we move on Prism.

I am happy.

@XVincentX XVincentX marked this pull request as ready for review May 1, 2020 03:46
Copy link
Contributor

@marcelltoth marcelltoth left a comment

Choose a reason for hiding this comment

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

Definitely improves readability for someone not-yet-FP-literate like me, too.

Copy link
Contributor

@karol-maciaszek karol-maciaszek left a comment

Choose a reason for hiding this comment

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

The Do is so cool. It simplifies a lot in a civilized way. I left few comments and I'm tentatively approving. Good luck with release!

packages/http/src/mocker/callback/callbacks.ts Outdated Show resolved Hide resolved
packages/http/src/mocker/index.ts Outdated Show resolved Hide resolved
packages/http/src/utils/runtimeExpression.ts Outdated Show resolved Hide resolved
@XVincentX XVincentX merged commit e01fa5a into master May 4, 2020
@XVincentX XVincentX deleted the use-do-simulator branch May 4, 2020 17:17
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.

None yet

3 participants