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

Fix Either and Maybe ::memoize() not loading everything #31

Merged
merged 1 commit into from
Dec 1, 2024

Conversation

Baptouuuu
Copy link
Member

Problem

When one creates a deferred Maybe and then compose it via a flatMap that returns a new deferred Maybe this creates internally a deferred monad containing a deferred monad. When the method memoize is called on it, it returns the underlying deferred monad.

This is problematic because the user thinks the whole composition has been memoized and potential IO operations associated with it have been done. But this is not the case.

The same problem happens with Either.

Solution

When memoize is called on these monads it recursively memoize the underlying monad. This way the recursion stops when a non deferred monad is found.

@Baptouuuu Baptouuuu added the bug Something isn't working label Dec 1, 2024
@Baptouuuu Baptouuuu self-assigned this Dec 1, 2024
@Baptouuuu Baptouuuu merged commit 3d68da9 into develop Dec 1, 2024
21 checks passed
@Baptouuuu Baptouuuu deleted the fix-memoization branch December 1, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant