Moduletomland-1.3.3.3Haskell2010
Toml.Codec.BiMap
SPDX-License-Identifier : MPL-2.0 Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable
Implementation of Tagged Partial Bidirectional Isomorphism. This module contains the BiMap type that represents conversion between two types with the possibility of failure.
See Toml.Codec.BiMap.Conversion for examples of BiMap with specific types. The BiMap concept is general and is not specific to TOML, but in this package most usages of BiMap are between TOML values and Haskell values.
- 3 types
- 7 values
- Packagetomland-1.3.3.3
- Exports10
- LanguageHaskell2010
- LicenceMPL-2.0
- SourceBiMap.hs
BiMap concept
4 declarationsInverts bidirectional mapping.
prism Creates BiMap from prism-like pair of functions. This combinator can be used to create BiMap for custom sum types like this:
data User
= Admin Integer -- id of admin
| Client Text -- name of the client
deriving (Show)
_Admin :: TomlBiMap User Integer
_Admin = Toml.prism Admin $ \case
Admin i -> Right i
other -> Toml.wrongConstructor "Admin" other
_Client :: TomlBiMap User Text
_Client = Toml.prism Client $ \case
Client n -> Right n
other -> Toml.wrongConstructor "Client" other
TOML BiMap
0 declarationsType
BiMap specialized to TOML error.
Error
Type of errors for TOML BiMap.
Constructors
WrongConstructor !Text !TextWrongValue !MatchErrorError for cases with wrong values
ArbitraryError !TextArbitrary textual error
Instances5Eq, Show, Generic, NFData, Rep
Eq TomlBiMapErrorDefined in tomland-1.3.3.3 · Toml.Codec.BiMapShow TomlBiMapErrorDefined in tomland-1.3.3.3 · Toml.Codec.BiMapGeneric TomlBiMapErrorDefined in tomland-1.3.3.3 · Toml.Codec.BiMapNFData TomlBiMapErrorDefined in tomland-1.3.3.3 · Toml.Codec.BiMaptype Rep TomlBiMapError = D1 ('MetaDataDefined in tomland-1.3.3.3 · Toml.Codec.BiMap"TomlBiMapError"
"Toml.Codec.BiMap"
"tomland-1.3.3.3-IZ1IPk9NxLy7CYVHjydqUA"
'False) (C1 ('MetaCons"WrongConstructor"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: (C1 ('MetaCons"WrongValue"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MatchError)) :+: C1 ('MetaCons"ArbitraryError"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text))))
wrongConstructor :: Show a=> TextName of the expected constructor
-> aActual value
-> Either TomlBiMapError b
Helper to construct WrongConstuctor error.
Converts TomlBiMapError into pretty human-readable text.
Smart constructors
mkAnyValueBiMap