blob: 3fa8973d23f0a250fc346ed7c150d9cd2f06224d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
module Data.Torrent.JSON
( omitLensPrefix
, omitRecordPrefix
) where
import Data.Aeson.TH
import Data.Char
import Data.List as L
-- | Ignore '_' prefix.
omitLensPrefix :: Options
omitLensPrefix = defaultOptions
{ fieldLabelModifier = L.dropWhile (== '_')
, constructorTagModifier = id
, allNullaryToStringTag = True
, omitNothingFields = True
}
mapWhile :: (a -> Bool) -> (a -> a) -> [a] -> [a]
mapWhile p f = go
where
go [] = []
go (x : xs)
| p x = f x : go xs
| otherwise = xs
omitRecordPrefix :: Options
omitRecordPrefix = omitLensPrefix
{ fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower
}
|