| Copyright | (c) Richard Lupton 2017 |
|---|---|
| License | BSD-3 |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Tyro
Description
Introduction
A small (artificial) example demonstrating how to use the types defined here.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
import Data.Tyro
import Data.Aeson (decode)
import Data.Text (Text)
json = "{\"key1\":[{\"key2\":41},{\"key2\":42}]}" :: Text
-- Extract [41, 42] inside the Tyro types
parsed = decode json :: Maybe ("key1" |>| List ("key2" |>| Parse Integer))
-- We can dispose of the types using unwrap: 'values' will have the value
-- Just [41, 42]
values :: Maybe [Integer]
values = fmap unwrap parsedBuilding types
type family (x :: Symbol) |>| (b :: *) :: * Source #
The type operator |>| provides a way of describing how to walk
down a JSON tree.
type family List (x :: *) :: * Source #
The List type operator constructs a parsing type for parsing
a list of JSON objects.