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 more Fold1 instances #215

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Topsii
Copy link
Contributor

@Topsii Topsii commented Nov 6, 2024

I omitted Costrong and ArrowLoop instances for Fold1. Fold already has a Costrong instance, but similar to the Monad instances mentioned in #214 (comment) I wonder whether it is safer to omit them to ensure Fold1s are streaming constant memory.

instance Costrong Fold1 where
    unfirst p = fmap f nonEmpty
      where
        f as = b
          where
            (b, d) = Control.Foldl.NonEmpty.fold1 p $ do
              a <- as
              pure (a, d)

instance ArrowLoop Fold1 where
    loop = unfirst

I also added nest for Fold1 and distinguished between both and both1 in the doctests.

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.

1 participant