Toml.Type.AnyValue

tomland-1.3.3.3: Bidirectional TOML serialization

Copyright | (c) 2018-2022 Kowainik
License | MPL-2.0
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | None
Language | Haskell2010

Toml.Type.AnyValue

Contents

- Matching

Description

Existential wrapper over `Value` type and matching functions.

Since: 0.0.0

Synopsis

- data AnyValue = AnyValue (Value t)
- reifyAnyValues :: forall (t :: TValue). Value t -> [AnyValue] -> Either TypeMismatchError [Value t]
- toMArray :: [AnyValue] -> Either MatchError (Value 'TArray)
- data MatchError = MatchError {
  - valueExpected :: !TValue
  - valueActual :: !AnyValue
  }
- mkMatchError :: forall (t :: TValue) a. TValue -> Value t -> Either MatchError a
- matchBool :: forall (t :: TValue). Value t -> Either MatchError Bool
- matchInteger :: forall (t :: TValue). Value t -> Either MatchError Integer
- matchDouble :: forall (t :: TValue). Value t -> Either MatchError Double
- matchText :: forall (t :: TValue). Value t -> Either MatchError Text
- matchZoned :: forall (t :: TValue). Value t -> Either MatchError ZonedTime
- matchLocal :: forall (t :: TValue). Value t -> Either MatchError LocalTime
- matchDay :: forall (t :: TValue). Value t -> Either MatchError Day
- matchHours :: forall (t :: TValue). Value t -> Either MatchError TimeOfDay
- matchArray :: forall a (t :: TValue). (AnyValue -> Either MatchError a) -> Value t -> Either MatchError [a]
- applyAsToAny :: forall r (t :: TValue). (AnyValue -> r) -> Value t -> r

# Documentation

data AnyValue #

Existential wrapper for `Value`.

Since: 0.0.0

Constructors

AnyValue (Value t) |

#### Instances

Instances details

NFData AnyValue # |
Instance details Defined in Toml.Type.AnyValue Methods rnf :: AnyValue -> () #
Show AnyValue # |
Instance details Defined in Toml.Type.AnyValue Methods showsPrec :: Int -> AnyValue -> ShowS # show :: AnyValue -> String # showList :: [AnyValue] -> ShowS #
Eq AnyValue # |
Instance details Defined in Toml.Type.AnyValue Methods (==) :: AnyValue -> AnyValue -> Bool # (/=) :: AnyValue -> AnyValue -> Bool #

reifyAnyValues :: forall (t :: TValue). Value t -> [AnyValue] -> Either TypeMismatchError [Value t] #

Checks whether all elements inside given list of `AnyValue` have the same type as given `Value`. Returns list of `Value t` without given `Value`.

toMArray :: [AnyValue] -> Either MatchError (Value 'TArray) #

Function for creating `Array` from list of `AnyValue`.

# Matching

data MatchError #

Value type mismatch error.

Constructors

MatchError |
Fields valueExpected :: !TValue valueActual :: !AnyValue

#### Instances

Instances details

NFData MatchError # |
Instance details Defined in Toml.Type.AnyValue Methods rnf :: MatchError -> () #
Generic MatchError # |
Instance details Defined in Toml.Type.AnyValue Associated Types
type Rep MatchError |
Instance details Defined in Toml.Type.AnyValue type Rep MatchError = D1 ('MetaData "MatchError" "Toml.Type.AnyValue" "tomland-1.3.3.3-EUmut0o3bp2HnXO9U1VNsY" 'False) (C1 ('MetaCons "MatchError" 'PrefixI 'True) (S1 ('MetaSel ('Just "valueExpected") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TValue) :*: S1 ('MetaSel ('Just "valueActual") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 AnyValue)))
Methods from :: MatchError -> Rep MatchError x # to :: Rep MatchError x -> MatchError #
Show MatchError # |
Instance details Defined in Toml.Type.AnyValue Methods showsPrec :: Int -> MatchError -> ShowS # show :: MatchError -> String # showList :: [MatchError] -> ShowS #
Eq MatchError # |
Instance details Defined in Toml.Type.AnyValue Methods (==) :: MatchError -> MatchError -> Bool # (/=) :: MatchError -> MatchError -> Bool #
type Rep MatchError # |
Instance details Defined in Toml.Type.AnyValue type Rep MatchError = D1 ('MetaData "MatchError" "Toml.Type.AnyValue" "tomland-1.3.3.3-EUmut0o3bp2HnXO9U1VNsY" 'False) (C1 ('MetaCons "MatchError" 'PrefixI 'True) (S1 ('MetaSel ('Just "valueExpected") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TValue) :*: S1 ('MetaSel ('Just "valueActual") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 AnyValue)))

mkMatchError :: forall (t :: TValue) a. TValue -> Value t -> Either MatchError a #

Helper function to create `MatchError`.

matchBool :: forall (t :: TValue). Value t -> Either MatchError Bool #

Extract `Bool` from `Value`.

matchInteger :: forall (t :: TValue). Value t -> Either MatchError Integer #

Extract `Integer` from `Value`.

matchDouble :: forall (t :: TValue). Value t -> Either MatchError Double #

Extract `Double` from `Value`.

matchText :: forall (t :: TValue). Value t -> Either MatchError Text #

Extract `Text` from `Value`.

matchZoned :: forall (t :: TValue). Value t -> Either MatchError ZonedTime #

Extract `ZonedTime` from `Value`.

matchLocal :: forall (t :: TValue). Value t -> Either MatchError LocalTime #

Extract `LocalTime` from `Value`.

matchDay :: forall (t :: TValue). Value t -> Either MatchError Day #

Extract `Day` from `Value`.

matchHours :: forall (t :: TValue). Value t -> Either MatchError TimeOfDay #

Extract `TimeOfDay` from `Value`.

matchArray :: forall a (t :: TValue). (AnyValue -> Either MatchError a) -> Value t -> Either MatchError [a] #

Extract list of elements of type `a` from array.

applyAsToAny :: forall r (t :: TValue). (AnyValue -> r) -> Value t -> r #

Make function that works with `AnyValue` also work with specific `Value`.