Copyright | Plow Technologies LLC |
---|---|

License | MIT License |

Maintainer | Scott Murphy |

Safe Haskell | None |

Language | Haskell2010 |

This is a library for creating composable converters between datatypes for the purpose of inserting into a groundhog database.

The idea is to get from a representation a, which does not have a type class 'PersistEntity a'
to one `b`

, which has that type class defined.

This allows lightweight types libraries to coexist with nice database representations.

- makeConverter :: (a -> b) -> (b -> a) -> Converter a b
- flipConverter :: Converter a b -> Converter b a
- composeConverter :: Converter a b -> Converter b c -> Converter a c
- fmapConverter :: Functor f => Converter a b -> Converter (f a) (f b)
- bicomposeConverter :: Converter a b -> Converter c d -> Converter (a, c) (b, d)
- firstConverter :: Converter a b -> Converter (a, c) (b, c)
- secondConverter :: Converter a b -> Converter (c, a) (c, b)
- jsonConverter :: (ToJSON a, FromJSON a) => Converter a ByteString
- integerConverter :: Converter Integer Int64
- mapConverter :: Ord k => Converter (Map k v) [(k, v)]
- bimapConverter :: (Ord a, Ord b) => Converter (Bimap a b) [(a, b)]
- intMapConverter :: Converter (IntMap a) [(Int, a)]
- type Converter a b = (a -> b, b -> a)

# Documentation

:: (a -> b) | Convert developer-facing type to database-storable type |

-> (b -> a) | Convert database-storable type to developer-facing type |

-> Converter a b |

Make a converter

There are preconditions on the input functions:

makeConverter f g

f (g x) = x

g (f x) = x

flipConverter :: Converter a b -> Converter b a Source

Reverse the direction of a converter

composeConverter :: Converter a b -> Converter b c -> Converter a c Source

Compose two converters

fmapConverter :: Functor f => Converter a b -> Converter (f a) (f b) Source

Map a converter over a functor

bicomposeConverter :: Converter a b -> Converter c d -> Converter (a, c) (b, d) Source

compose a First and Second Converter

firstConverter :: Converter a b -> Converter (a, c) (b, c) Source

Convert only the first element of a pair

secondConverter :: Converter a b -> Converter (c, a) (c, b) Source

Convert only the second element of a pair

jsonConverter :: (ToJSON a, FromJSON a) => Converter a ByteString Source

Convert via to and from JSON

mapConverter :: Ord k => Converter (Map k v) [(k, v)] Source

Convert a `Map`

to a list of key-value pairs

bimapConverter :: (Ord a, Ord b) => Converter (Bimap a b) [(a, b)] Source

Convert a `Bimap`

to a list of key-value pairs

intMapConverter :: Converter (IntMap a) [(Int, a)] Source