| Copyright | (C) CSIRO 2017-2018 |
|---|---|
| License | BSD3 |
| Maintainer | George Wilson <george.wilson@data61.csiro.au> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Sv
Description
This module exports most of the other modules from the package. It is intended to be imported unqualified, along with some qualified imports for the Data.Sv.Decode and Data.Sv.Encode modules as needed.
import Data.Sv import qualified Data.Sv.Decode as D import qualified Data.Sv.Encode as E
Synopsis
- parseDecode :: Decode' ByteString a -> ParseOptions -> ByteString -> DecodeValidation ByteString [a]
- parseDecodeFromFile :: MonadIO m => Decode' ByteString a -> ParseOptions -> FilePath -> m (DecodeValidation ByteString [a])
- parseDecodeFromDsvCursor :: Decode' ByteString a -> ParseOptions -> DsvCursor -> DecodeValidation ByteString [a]
- parseDecodeNamed :: NameDecode' ByteString a -> ParseOptions -> ByteString -> DecodeValidation ByteString [a]
- parseDecodeNamedFromFile :: MonadIO m => NameDecode' ByteString a -> ParseOptions -> FilePath -> m (DecodeValidation ByteString [a])
- parseDecodeNamedFromDsvCursor :: NameDecode' ByteString a -> ParseOptions -> DsvCursor -> DecodeValidation ByteString [a]
- decode :: Traversable f => Decode' ByteString a -> f (Vector ByteString) -> DecodeValidation ByteString (f a)
- decodeMay :: DecodeError e -> (s -> Maybe a) -> Decode e s a
- decodeEither :: (s -> Either (DecodeError e) a) -> Decode e s a
- decodeEither' :: (e -> DecodeError e') -> (s -> Either e a) -> Decode e' s a
- (.:) :: Ord s => s -> Decode' s a -> NameDecode' s a
- (>>==) :: Decode e s a -> (a -> DecodeValidation e b) -> Decode e s b
- (==<<) :: (a -> DecodeValidation e b) -> Decode e s a -> Decode e s b
- module Data.Sv.Parse
- encode :: Encode a -> EncodeOptions -> [a] -> ByteString
- encodeToFile :: Encode a -> EncodeOptions -> [a] -> FilePath -> IO ()
- encodeToHandle :: Encode a -> EncodeOptions -> [a] -> Handle -> IO ()
- encodeBuilder :: Encode a -> EncodeOptions -> [a] -> Builder
- encodeNamed :: NameEncode a -> EncodeOptions -> [a] -> ByteString
- encodeNamedToFile :: NameEncode a -> EncodeOptions -> [a] -> FilePath -> IO ()
- encodeNamedToHandle :: NameEncode a -> EncodeOptions -> [a] -> Handle -> IO ()
- encodeNamedBuilder :: NameEncode a -> EncodeOptions -> [a] -> Builder
- encodeRow :: Encode a -> EncodeOptions -> a -> ByteString
- (=:) :: Builder -> Encode a -> NameEncode a
- module Data.Sv.Structure
- class Functor f => Alt (f :: Type -> Type) where
- (<!>) :: f a -> f a -> f a
- some :: Applicative f => f a -> f [a]
- many :: Applicative f => f a -> f [a]
- class Contravariant (f :: Type -> Type) where
- class Contravariant f => Divisible (f :: Type -> Type) where
- divided :: Divisible f => f a -> f b -> f (a, b)
- class Divisible f => Decidable (f :: Type -> Type) where
- chosen :: Decidable f => f b -> f c -> f (Either b c)
- data Validation err a
Decoding
parseDecode :: Decode' ByteString a -> ParseOptions -> ByteString -> DecodeValidation ByteString [a] Source #
Parse a ByteString as an Sv, and then decode it with the given decoder.
parseDecodeFromFile :: MonadIO m => Decode' ByteString a -> ParseOptions -> FilePath -> m (DecodeValidation ByteString [a]) Source #
Load a file, parse it, and decode it.
parseDecodeFromDsvCursor :: Decode' ByteString a -> ParseOptions -> DsvCursor -> DecodeValidation ByteString [a] Source #
Decode from a DsvCursor
parseDecodeNamed :: NameDecode' ByteString a -> ParseOptions -> ByteString -> DecodeValidation ByteString [a] Source #
Parse a ByteString as an Sv, and then decode it with the given colum
based decoder.
parseDecodeNamedFromFile :: MonadIO m => NameDecode' ByteString a -> ParseOptions -> FilePath -> m (DecodeValidation ByteString [a]) Source #
Load a file, parse it, and decode it by column.
parseDecodeNamedFromDsvCursor :: NameDecode' ByteString a -> ParseOptions -> DsvCursor -> DecodeValidation ByteString [a] Source #
Decode from a DsvCursor
decode :: Traversable f => Decode' ByteString a -> f (Vector ByteString) -> DecodeValidation ByteString (f a) #
decodeEither :: (s -> Either (DecodeError e) a) -> Decode e s a #
decodeEither' :: (e -> DecodeError e') -> (s -> Either e a) -> Decode e' s a #
module Data.Sv.Parse
Encoding
encode :: Encode a -> EncodeOptions -> [a] -> ByteString #
encodeToFile :: Encode a -> EncodeOptions -> [a] -> FilePath -> IO () #
encodeToHandle :: Encode a -> EncodeOptions -> [a] -> Handle -> IO () #
encodeBuilder :: Encode a -> EncodeOptions -> [a] -> Builder #
encodeNamed :: NameEncode a -> EncodeOptions -> [a] -> ByteString #
encodeNamedToFile :: NameEncode a -> EncodeOptions -> [a] -> FilePath -> IO () #
encodeNamedToHandle :: NameEncode a -> EncodeOptions -> [a] -> Handle -> IO () #
encodeNamedBuilder :: NameEncode a -> EncodeOptions -> [a] -> Builder #
encodeRow :: Encode a -> EncodeOptions -> a -> ByteString #
Structure
module Data.Sv.Structure
Re-exports from contravariant, validation, and semigroupoids
class Functor f => Alt (f :: Type -> Type) where #
Minimal complete definition
Instances
| Alt [] | |
Defined in Data.Functor.Alt | |
| Alt Maybe | |
| Alt IO | |
| Alt First | |
| Alt Last | |
| Alt Option | |
| Alt First | |
| Alt Last | |
| Alt NonEmpty | |
| Alt IntMap | |
| Alt Seq | |
| Alt (Either a) | |
| Alt (V1 :: Type -> Type) | |
| Alt (U1 :: Type -> Type) | |
| MonadPlus m => Alt (WrappedMonad m) | |
Defined in Data.Functor.Alt Methods (<!>) :: WrappedMonad m a -> WrappedMonad m a -> WrappedMonad m a # some :: Applicative (WrappedMonad m) => WrappedMonad m a -> WrappedMonad m [a] # many :: Applicative (WrappedMonad m) => WrappedMonad m a -> WrappedMonad m [a] # | |
| Alt (Proxy :: Type -> Type) | |
| Ord k => Alt (Map k) | |
| Apply f => Alt (ListT f) | |
| Alt f => Alt (Lift f) | |
| (Bind f, Monad f) => Alt (MaybeT f) | |
| Alt (Validation err) | |
Defined in Data.Validation Methods (<!>) :: Validation err a -> Validation err a -> Validation err a # some :: Applicative (Validation err) => Validation err a -> Validation err [a] # many :: Applicative (Validation err) => Validation err a -> Validation err [a] # | |
| Alternative f => Alt (WrappedApplicative f) | |
Defined in Data.Functor.Alt Methods (<!>) :: WrappedApplicative f a -> WrappedApplicative f a -> WrappedApplicative f a # some :: Applicative (WrappedApplicative f) => WrappedApplicative f a -> WrappedApplicative f [a] # many :: Applicative (WrappedApplicative f) => WrappedApplicative f a -> WrappedApplicative f [a] # | |
| Alt f => Alt (Yoneda f) | |
Defined in Data.Functor.Yoneda Methods (<!>) :: Yoneda f a -> Yoneda f a -> Yoneda f a # some :: Applicative (Yoneda f) => Yoneda f a -> Yoneda f [a] # many :: Applicative (Yoneda f) => Yoneda f a -> Yoneda f [a] # | |
| Alt (ReifiedFold s) | |
Defined in Control.Lens.Reified Methods (<!>) :: ReifiedFold s a -> ReifiedFold s a -> ReifiedFold s a # some :: Applicative (ReifiedFold s) => ReifiedFold s a -> ReifiedFold s [a] # many :: Applicative (ReifiedFold s) => ReifiedFold s a -> ReifiedFold s [a] # | |
| Alt f => Alt (Rec1 f) | |
| ArrowPlus a => Alt (WrappedArrow a b) | |
Defined in Data.Functor.Alt Methods (<!>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 # some :: Applicative (WrappedArrow a b) => WrappedArrow a b a0 -> WrappedArrow a b [a0] # many :: Applicative (WrappedArrow a b) => WrappedArrow a b a0 -> WrappedArrow a b [a0] # | |
| Alt f => Alt (IdentityT f) | |
| (Bind f, Monad f) => Alt (ErrorT e f) | |
| (Bind f, Monad f, Semigroup e) => Alt (ExceptT e f) | |
| Alt f => Alt (StateT e f) | |
| Alt f => Alt (StateT e f) | |
| Alt f => Alt (WriterT w f) | |
| Alt f => Alt (WriterT w f) | |
| Alt f => Alt (Reverse f) | |
| Alt f => Alt (Backwards f) | |
| Alt (Decode e s) | |
Defined in Data.Sv.Decode.Type Methods (<!>) :: Decode e s a -> Decode e s a -> Decode e s a # some :: Applicative (Decode e s) => Decode e s a -> Decode e s [a] # many :: Applicative (Decode e s) => Decode e s a -> Decode e s [a] # | |
| Alt (NameDecode e s) | |
Defined in Data.Sv.Decode.Type Methods (<!>) :: NameDecode e s a -> NameDecode e s a -> NameDecode e s a # some :: Applicative (NameDecode e s) => NameDecode e s a -> NameDecode e s [a] # many :: Applicative (NameDecode e s) => NameDecode e s a -> NameDecode e s [a] # | |
| Alt (ReifiedIndexedFold i s) | |
Defined in Control.Lens.Reified Methods (<!>) :: ReifiedIndexedFold i s a -> ReifiedIndexedFold i s a -> ReifiedIndexedFold i s a # some :: Applicative (ReifiedIndexedFold i s) => ReifiedIndexedFold i s a -> ReifiedIndexedFold i s [a] # many :: Applicative (ReifiedIndexedFold i s) => ReifiedIndexedFold i s a -> ReifiedIndexedFold i s [a] # | |
| (Alt f, Alt g) => Alt (f :*: g) | |
| (Alt f, Alt g) => Alt (Product f g) | |
| Alt f => Alt (ReaderT e f) | |
| Alt f => Alt (M1 i c f) | |
| (Alt f, Functor g) => Alt (Compose f g) | |
| Alt f => Alt (RWST r w s f) | |
| Alt f => Alt (RWST r w s f) | |
class Contravariant (f :: Type -> Type) where #
The class of contravariant functors.
Whereas in Haskell, one can think of a Functor as containing or producing
values, a contravariant functor is a functor that can be thought of as
consuming values.
As an example, consider the type of predicate functions a -> Bool. One
such predicate might be negative x = x < 0, which
classifies integers as to whether they are negative. However, given this
predicate, we can re-use it in other situations, providing we have a way to
map values to integers. For instance, we can use the negative predicate
on a person's bank balance to work out if they are currently overdrawn:
newtype Predicate a = Predicate { getPredicate :: a -> Bool }
instance Contravariant Predicate where
contramap f (Predicate p) = Predicate (p . f)
| `- First, map the input...
`----- then apply the predicate.
overdrawn :: Predicate Person
overdrawn = contramap personBankBalance negative
Any instance should be subject to the following laws:
contramap id = id contramap f . contramap g = contramap (g . f)
Note, that the second law follows from the free theorem of the type of
contramap and the first law, so you need only check that the former
condition holds.
Minimal complete definition
Instances
class Contravariant f => Divisible (f :: Type -> Type) where #
Instances
class Divisible f => Decidable (f :: Type -> Type) where #
Instances
data Validation err a #
Instances
| Bitraversable Validation | |
Defined in Data.Validation Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Validation a b -> f (Validation c d) # | |
| Bifoldable Validation | |
Defined in Data.Validation Methods bifold :: Monoid m => Validation m m -> m # bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> Validation a b -> m # bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> Validation a b -> c # bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> Validation a b -> c # | |
| Bifunctor Validation | |
Defined in Data.Validation Methods bimap :: (a -> b) -> (c -> d) -> Validation a c -> Validation b d # first :: (a -> b) -> Validation a c -> Validation b c # second :: (b -> c) -> Validation a b -> Validation a c # | |
| Validate Validation | |
Defined in Data.Validation Methods _Validation :: Iso (Validation e a) (Validation g b) (Validation e a) (Validation g b) _Either :: Iso (Validation e a) (Validation g b) (Either e a) (Either g b) | |
| Swapped Validation | |
Defined in Data.Validation Methods swapped :: Iso (Validation a b) (Validation c d) (Validation b a) (Validation d c) | |
| Functor (Validation err) | |
Defined in Data.Validation Methods fmap :: (a -> b) -> Validation err a -> Validation err b # (<$) :: a -> Validation err b -> Validation err a # | |
| Semigroup err => Applicative (Validation err) | |
Defined in Data.Validation Methods pure :: a -> Validation err a # (<*>) :: Validation err (a -> b) -> Validation err a -> Validation err b # liftA2 :: (a -> b -> c) -> Validation err a -> Validation err b -> Validation err c # (*>) :: Validation err a -> Validation err b -> Validation err b # (<*) :: Validation err a -> Validation err b -> Validation err a # | |
| Foldable (Validation err) | |
Defined in Data.Validation Methods fold :: Monoid m => Validation err m -> m # foldMap :: Monoid m => (a -> m) -> Validation err a -> m # foldr :: (a -> b -> b) -> b -> Validation err a -> b # foldr' :: (a -> b -> b) -> b -> Validation err a -> b # foldl :: (b -> a -> b) -> b -> Validation err a -> b # foldl' :: (b -> a -> b) -> b -> Validation err a -> b # foldr1 :: (a -> a -> a) -> Validation err a -> a # foldl1 :: (a -> a -> a) -> Validation err a -> a # toList :: Validation err a -> [a] # null :: Validation err a -> Bool # length :: Validation err a -> Int # elem :: Eq a => a -> Validation err a -> Bool # maximum :: Ord a => Validation err a -> a # minimum :: Ord a => Validation err a -> a # sum :: Num a => Validation err a -> a # product :: Num a => Validation err a -> a # | |
| Traversable (Validation err) | |
Defined in Data.Validation Methods traverse :: Applicative f => (a -> f b) -> Validation err a -> f (Validation err b) # sequenceA :: Applicative f => Validation err (f a) -> f (Validation err a) # mapM :: Monad m => (a -> m b) -> Validation err a -> m (Validation err b) # sequence :: Monad m => Validation err (m a) -> m (Validation err a) # | |
| Semigroup err => Apply (Validation err) | |
Defined in Data.Validation Methods (<.>) :: Validation err (a -> b) -> Validation err a -> Validation err b (.>) :: Validation err a -> Validation err b -> Validation err b (<.) :: Validation err a -> Validation err b -> Validation err a liftF2 :: (a -> b -> c) -> Validation err a -> Validation err b -> Validation err c | |
| Alt (Validation err) | |
Defined in Data.Validation Methods (<!>) :: Validation err a -> Validation err a -> Validation err a # some :: Applicative (Validation err) => Validation err a -> Validation err [a] # many :: Applicative (Validation err) => Validation err a -> Validation err [a] # | |
| (Eq err, Eq a) => Eq (Validation err a) | |
Defined in Data.Validation Methods (==) :: Validation err a -> Validation err a -> Bool # (/=) :: Validation err a -> Validation err a -> Bool # | |
| (Data err, Data a) => Data (Validation err a) | |
Defined in Data.Validation Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Validation err a -> c (Validation err a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Validation err a) # toConstr :: Validation err a -> Constr # dataTypeOf :: Validation err a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Validation err a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Validation err a)) # gmapT :: (forall b. Data b => b -> b) -> Validation err a -> Validation err a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Validation err a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Validation err a -> r # gmapQ :: (forall d. Data d => d -> u) -> Validation err a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Validation err a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Validation err a -> m (Validation err a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Validation err a -> m (Validation err a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Validation err a -> m (Validation err a) # | |
| (Ord err, Ord a) => Ord (Validation err a) | |
Defined in Data.Validation Methods compare :: Validation err a -> Validation err a -> Ordering # (<) :: Validation err a -> Validation err a -> Bool # (<=) :: Validation err a -> Validation err a -> Bool # (>) :: Validation err a -> Validation err a -> Bool # (>=) :: Validation err a -> Validation err a -> Bool # max :: Validation err a -> Validation err a -> Validation err a # min :: Validation err a -> Validation err a -> Validation err a # | |
| (Show err, Show a) => Show (Validation err a) | |
Defined in Data.Validation Methods showsPrec :: Int -> Validation err a -> ShowS # show :: Validation err a -> String # showList :: [Validation err a] -> ShowS # | |
| Generic (Validation err a) | |
Defined in Data.Validation Associated Types type Rep (Validation err a) :: Type -> Type # Methods from :: Validation err a -> Rep (Validation err a) x # to :: Rep (Validation err a) x -> Validation err a # | |
| Semigroup e => Semigroup (Validation e a) | |
Defined in Data.Validation Methods (<>) :: Validation e a -> Validation e a -> Validation e a # sconcat :: NonEmpty (Validation e a) -> Validation e a # stimes :: Integral b => b -> Validation e a -> Validation e a # | |
| Monoid e => Monoid (Validation e a) | |
Defined in Data.Validation Methods mempty :: Validation e a # mappend :: Validation e a -> Validation e a -> Validation e a # mconcat :: [Validation e a] -> Validation e a # | |
| (NFData e, NFData a) => NFData (Validation e a) | |
Defined in Data.Validation Methods rnf :: Validation e a -> () # | |
| type Rep (Validation err a) | |
Defined in Data.Validation type Rep (Validation err a) = D1 (MetaData "Validation" "Data.Validation" "validation-1-525bfa08079193cc08bc9c9f0f4418dd7d0cbef3c74aea1c02dfe05e2d659ef1" False) (C1 (MetaCons "Failure" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 err)) :+: C1 (MetaCons "Success" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))) | |