diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-07 23:10:27 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-07 23:10:27 +0400 |
commit | 1ae7d4877a2a30131babbee54bc0c24651eaba90 (patch) | |
tree | 1d2b6835d70a546859569933d0a34037b029d7c5 /src/Data/Torrent/JSON.hs | |
parent | 44fc77ee51b5aef9d43e3d384845d73646ea1d0e (diff) |
Move JSON options to separate module
Diffstat (limited to 'src/Data/Torrent/JSON.hs')
-rw-r--r-- | src/Data/Torrent/JSON.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Data/Torrent/JSON.hs b/src/Data/Torrent/JSON.hs new file mode 100644 index 00000000..3fa8973d --- /dev/null +++ b/src/Data/Torrent/JSON.hs | |||
@@ -0,0 +1,31 @@ | |||
1 | module Data.Torrent.JSON | ||
2 | ( omitLensPrefix | ||
3 | , omitRecordPrefix | ||
4 | ) where | ||
5 | |||
6 | import Data.Aeson.TH | ||
7 | import Data.Char | ||
8 | import Data.List as L | ||
9 | |||
10 | |||
11 | -- | Ignore '_' prefix. | ||
12 | omitLensPrefix :: Options | ||
13 | omitLensPrefix = defaultOptions | ||
14 | { fieldLabelModifier = L.dropWhile (== '_') | ||
15 | , constructorTagModifier = id | ||
16 | , allNullaryToStringTag = True | ||
17 | , omitNothingFields = True | ||
18 | } | ||
19 | |||
20 | mapWhile :: (a -> Bool) -> (a -> a) -> [a] -> [a] | ||
21 | mapWhile p f = go | ||
22 | where | ||
23 | go [] = [] | ||
24 | go (x : xs) | ||
25 | | p x = f x : go xs | ||
26 | | otherwise = xs | ||
27 | |||
28 | omitRecordPrefix :: Options | ||
29 | omitRecordPrefix = omitLensPrefix | ||
30 | { fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower | ||
31 | } \ No newline at end of file | ||