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

More transformers instances #366

Merged
merged 19 commits into from
Mar 13, 2020
Merged

More transformers instances #366

merged 19 commits into from
Mar 13, 2020

Conversation

robrix
Copy link
Contributor

@robrix robrix commented Mar 13, 2020

This PR adds Algebra instances for a few more types from transformers, namely including two only available in 0.5.6+.

@robrix robrix changed the base branch from no-exit to master March 13, 2020 06:14
Comment on lines +210 to +214
instance Algebra sig m => Algebra (Empty :+: sig) (Maybe.MaybeT m) where
alg hdl sig ctx = case sig of
L Empty -> Maybe.MaybeT (pure Nothing)
R other -> Maybe.MaybeT $ thread (maybe (pure Nothing) Maybe.runMaybeT) hdl other (Just ctx)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I honestly don’t know why I didn’t implement this before.

Comment on lines +228 to +229
newtype Swap s a = Swap { getSwap :: (a, s) }
deriving (Functor)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is handy for giving us a Functor instance for the backwards pairs transformers is so fond of.

Comment on lines +282 to +289
#if MIN_VERSION_transformers(0,5,6)
instance (Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (Writer.CPS.WriterT w m) where
alg hdl sig ctx = case sig of
L (Tell w) -> ctx <$ Writer.CPS.tell w
L (Listen m) -> swapAndLift <$> Writer.CPS.listen (hdl (m <$ ctx))
L (Censor f m) -> Writer.CPS.censor f (hdl (m <$ ctx))
R other -> Writer.CPS.writerT $ getSwap <$> thread (\ (Swap (x, s)) -> Swap . fmap (mappend s) <$> Writer.CPS.runWriterT x) hdl other (Swap (ctx, mempty))
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had implemented this before, but removed it because it was unavailable on some of our ghcs. But since we added CPP to support the Ap instance I figured I might as well add it back in.

@robrix robrix added this to the 1.1.0.0 milestone Mar 13, 2020
@robrix robrix mentioned this pull request Mar 13, 2020
3 tasks
@robrix robrix merged commit 62caa61 into master Mar 13, 2020
@robrix robrix deleted the more-transformers-instances branch March 13, 2020 06:32
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

1 participant