From 146518768ba1959fc5b0688074cbc942baa970b2 Mon Sep 17 00:00:00 2001 From: Gautier DI FOLCO Date: Sat, 1 Oct 2022 18:22:30 +0200 Subject: [PATCH] Add Codec's Selective instance --- src/Toml/Codec/Types.hs | 9 +++++++++ tomland.cabal | 1 + 2 files changed, 10 insertions(+) diff --git a/src/Toml/Codec/Types.hs b/src/Toml/Codec/Types.hs index ca112d0..1b4d85b 100644 --- a/src/Toml/Codec/Types.hs +++ b/src/Toml/Codec/Types.hs @@ -35,6 +35,7 @@ module Toml.Codec.Types import Control.Applicative (Alternative (..), liftA2) import Control.Monad.State (MonadState (..)) +import Control.Selective (Selective (..)) import Data.Bifunctor (first) import Validation (Validation (..)) @@ -137,6 +138,14 @@ infixl 3 f g = \a -> f a <|> g a {-# INLINE () #-} +-- | @since 1.3.4 +instance Selective (Codec i) where + select branched onLeft = Codec + { codecRead = \o -> (`either` id) <$> codecRead onLeft o <*> codecRead branched o + , codecWrite = \i -> (`either` id) <$> codecWrite onLeft i <*> codecWrite branched i + } + {-# INLINE select #-} + {- | Mutable context for TOML conversion. We are introducing our own implemetation of state with 'MonadState' instance due to some limitation in the design connected to the usage of State. diff --git a/tomland.cabal b/tomland.cabal index 9581955..3a5e42c 100644 --- a/tomland.cabal +++ b/tomland.cabal @@ -137,6 +137,7 @@ library , megaparsec >= 7.0.5 && < 9.3 , mtl ^>= 2.2 , parser-combinators >= 1.1.0 && < 1.4 + , selective ^>= 0.4.2 , text >= 1.2 && < 2.1 , time >= 1.8 && < 1.14 , transformers >= 0.5 && < 0.7