Skip to content

Add eager mapping operation for Async #178

Description

@treeowl

I noticed that Async has a Functor instance, which changes the result of an Async. But it (necessarily) does so entirely lazily; there's no way to ensure that computation is completed by the time wait returns. I suggest adding the following (by whatever name you like):

mapAsync :: (a -> Solo b) -> Async a -> Async b
mapAsync f (Async a w) = Async a $ w >>= \case
  Left e -> pure (Left e)
  Right r | MkSolo r' <- f r -> pure (Right r')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions