polysemy-vinyl 0.1.1.0 → 0.1.2.0
raw patch · 3 files changed
+68/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Polysemy.Vinyl: endRecInput :: Sem (Input (Rec f '[]) : r) a -> Sem r a
+ Polysemy.Vinyl: separateRecInput :: forall f x xs r a. Members '[Input (Rec f xs), Input (f x)] r => Sem (Input (Rec f (x : xs)) : r) a -> Sem r a
+ Polysemy.Vinyl: separateRecInput' :: forall f x xs r a. Sem (Input (Rec f (x : xs)) : r) a -> Sem (Input (f x) : (Input (Rec f xs) : r)) a
+ Polysemy.Vinyl: stripRecInput :: forall f x xs r a. Members '[Input (f x)] (Input (Rec f xs) : r) => Sem (Input (Rec f (x : xs)) : r) a -> Sem (Input (Rec f xs) : r) a
Files
- ChangeLog.md +5/−0
- polysemy-vinyl.cabal +1/−1
- src/Polysemy/Vinyl.hs +62/−4
ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for polysemy-vinyl +## v0.1.2.0++* Add `separateRecInput`, `separateRecInput'`, `stripRecInput`, `endRecInput`.+* Inline everything.+ ## v0.1.1.0 * Enable `PolyKinds`.
polysemy-vinyl.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: polysemy-vinyl-version: 0.1.1.0+version: 0.1.2.0 synopsis: Functions for mapping vinyl records in polysemy. description: Extra functions for using vinyl records in polysemy. category: Polysemy Vinyl
src/Polysemy/Vinyl.hs view
@@ -6,18 +6,28 @@ Extra functions for using vinyl records with polysemy. -}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE BlockArguments #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeOperators #-} module Polysemy.Vinyl ( rContramapInput , rContramapInput' , rMapOutput , rMapOutput'+, separateRecInput+, separateRecInput'+, stripRecInput+, endRecInput ) where import Control.Arrow+import Control.Applicative import Data.Vinyl import Polysemy import Polysemy.Extra@@ -34,6 +44,7 @@ -> Sem (Input (Rec g xs) ': r) a -> Sem r a rContramapInput k = contramapInput (rmap k)+{-# INLINE rContramapInput #-} -- | Reinterpreting version of `rContramapInput`. --@@ -44,6 +55,7 @@ -> Sem (Input (Rec g xs) ': r) a -> Sem (Input (Rec f xs) ': r) a rContramapInput' k = raiseUnder >>> rContramapInput k+{-# INLINE rContramapInput' #-} -- | Map an `Output` containing a `Rec` covariantly via a natural transformation. -- Uses `rmap`.@@ -55,6 +67,7 @@ -> Sem (Output (Rec f xs) ': r) a -> Sem r a rMapOutput k = mapOutput (rmap k)+{-# INLINE rMapOutput #-} -- | Reinterpreting version of `rMapOutput`. --@@ -65,3 +78,48 @@ -> Sem (Output (Rec f xs) ': r) a -> Sem (Output (Rec g xs) ': r) a rMapOutput' k = raiseUnder >>> rMapOutput k+{-# INLINE rMapOutput' #-}++-- | Separate one of the fields of an `Input` `Rec` into its own `Input`.+--+-- @since 0.1.2.0+separateRecInput :: forall f x xs r a.+ Members '[ Input (Rec f xs)+ , Input (f x)] r+ => Sem (Input (Rec f (x ': xs)) ': r) a+ -> Sem r a+separateRecInput = interpret \case+ Input -> liftA2 (:&) (input @(f x)) (input @(Rec f xs))+{-# INLINE separateRecInput #-}++-- | Reinterpreting version of `separateRecInput`. This assumes you want to handle+-- the separated case first.+--+-- @since 0.1.2.0+separateRecInput' :: forall f x xs r a.+ Sem (Input (Rec f (x ': xs)) ': r) a+ -> Sem (Input (f x) ': Input (Rec f xs) ': r) a+separateRecInput'= reinterpret2 \case+ Input -> liftA2 (:&) (input @(f x)) (raise $ input @(Rec f xs))+{-# INLINE separateRecInput' #-}++-- | Like `separateRecInput`, but places the remainer of the `Rec` at the head+-- of the list while pushing the case into the stack. This is useful when you+-- want to eliminate the record first by repeated applications of `stripRecInput`.+--+-- @since 0.1.2.0+stripRecInput :: forall f x xs r a.+ Members '[Input (f x)] (Input (Rec f xs) ': r)+ => Sem (Input (Rec f (x ': xs)) ': r) a+ -> Sem (Input (Rec f xs) ': r) a+stripRecInput = reinterpret \case+ Input -> liftA2 (:&) (input @(f x)) (input @(Rec f xs))+{-# INLINE stripRecInput #-}++-- | Discard a depleted `Rec` `Input` by returning `RNil`.+--+-- @since 0.1.2.0+endRecInput :: Sem (Input (Rec f '[]) ': r) a -> Sem r a+endRecInput = interpret \case+ Input -> return $ RNil+{-# INLINE endRecInput #-}