Safe Haskell | None |
---|---|
Language | Haskell2010 |
Database.InfluxDB.Decode
- class FromSeries a where
- parseSeries :: Series -> Parser a
- fromSeries :: FromSeries a => Series -> Either String a
- class FromSeriesData a where
- fromSeriesData :: FromSeriesData a => SeriesData -> Either String [a]
- fromSeriesData_ :: FromSeriesData a => SeriesData -> [a]
- withValues :: (Vector Value -> ValueParser a) -> Vector Column -> Vector Value -> Parser a
- (.:) :: FromValue a => Vector Value -> Column -> ValueParser a
- (.:?) :: FromValue a => Vector Value -> Column -> ValueParser (Maybe a)
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- class FromValue a where
- parseValue :: Value -> Parser a
- fromValue :: FromValue a => Value -> Either String a
- data Parser a
- data ValueParser a
- typeMismatch :: String -> Value -> Parser a
Documentation
class FromSeries a where Source
A type that can be converted from a Series
.
Methods
parseSeries :: Series -> Parser a Source
Instances
fromSeries :: FromSeries a => Series -> Either String a Source
Converte a value from a Series
, failing if the types do not match.
class FromSeriesData a where Source
A type that can be converted from a SeriesData
. A typical implementation
is as follows.
import Control.Applicative ((<$>), (<*>)) import qualified Data.Vector as V data Event = Event Text EventType data EventType = Login | Logout instance FromSeriesData Event where parseSeriesData = withValues $ \values -> Event <$> values .: "user" <*> values .: "type" instance FromValue EventType
Instances
fromSeriesData :: FromSeriesData a => SeriesData -> Either String [a] Source
Converte a value from a SeriesData
, failing if the types do not match.
fromSeriesData_ :: FromSeriesData a => SeriesData -> [a] Source
Same as fromSeriesData
but ignores parse errors and returns only
successful data.
withValues :: (Vector Value -> ValueParser a) -> Vector Column -> Vector Value -> Parser a Source
Helper function to define parseSeriesData
from ValueParser
s.
(.:) :: FromValue a => Vector Value -> Column -> ValueParser a Source
Retrieve the value associated with the given column. The result is empty
if the column is not present or the value cannot be converted to the desired
type.
(.:?) :: FromValue a => Vector Value -> Column -> ValueParser (Maybe a) Source
Retrieve the value associated with the given column. The result is
Nothing
if the column is not present or the value cannot be converted to
the desired type.
(.!=) :: Parser (Maybe a) -> a -> Parser a Source
Helper for use in combination with .:?
to provide default values for
optional columns.
class FromValue a where Source
A type that can be converted from a Value
.
Methods
parseValue :: Value -> Parser a Source
fromValue :: FromValue a => Value -> Either String a Source
Converte a value from a Value
, failing if the types do not match.
data ValueParser a Source
Instances
typeMismatch :: String -> Value -> Parser a Source