File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ module Toml.Codec.Types
3535
3636import Control.Applicative (Alternative (.. ), liftA2 )
3737import Control.Monad.State (MonadState (.. ))
38+ import Control.Selective (Selective (.. ))
3839import Data.Bifunctor (first )
3940import Validation (Validation (.. ))
4041
@@ -137,6 +138,14 @@ infixl 3 <!>
137138f <!> g = \ a -> f a <|> g a
138139{-# INLINE (<!>) #-}
139140
141+ -- | @since 1.3.4
142+ instance Selective (Codec i ) where
143+ select branched onLeft = Codec
144+ { codecRead = \ o -> (`either` id ) <$> codecRead onLeft o <*> codecRead branched o
145+ , codecWrite = \ i -> (`either` id ) <$> codecWrite onLeft i <*> codecWrite branched i
146+ }
147+ {-# INLINE select #-}
148+
140149{- | Mutable context for TOML conversion.
141150We are introducing our own implemetation of state with 'MonadState' instance due
142151to some limitation in the design connected to the usage of State.
Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ library
133133 , megaparsec >= 7.0.5 && < 9.3
134134 , mtl ^>= 2.2
135135 , parser-combinators >= 1.1.0 && < 1.4
136+ , selective ^>= 0.4.2
136137 , text ^>= 1.2
137138 , time >= 1.8 && < 1.14
138139 , transformers >= 0.5 && < 0.7
You can’t perform that action at this time.
0 commit comments