git.iko.soy/typeable/bloodhound
on master help sign in
Refactor: DRY aggregation result parsing
commitb966b12defc759d7d495a15ece898592545006e3 authorMHova <mho@sumall.com> dateWed 3 Feb 2016, 17:30 (11 years ago) parent6e1e445
1 file changed+6−5
src/Database/Bloodhound/Types.hs+6−5
src/Database/Bloodhound/Types.hs+6−5
@@ -1814,15 +1814,16 @@ data DateRangeResult = DateRangeResult { dateRangeKey :: Text
18141814 , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic, Typeable)
18151815
18161816toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1817−toTerms t a = M.lookup t a >>= deserialize
1818− where deserialize = parseMaybe parseJSON
1817+toTerms = toAggResult
18191818
18201819toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1821−toDateHistogram t a = M.lookup t a >>= deserialize
1822− where deserialize = parseMaybe parseJSON
1820+toDateHistogram = toAggResult
18231821
18241822toMissing :: Text -> AggregationResults -> Maybe MissingResult
1825−toMissing t a = M.lookup t a >>= deserialize
1823+toMissing = toAggResult
1824+
1825+toAggResult :: (FromJSON a) => Text -> AggregationResults -> Maybe a
1826+toAggResult t a = M.lookup t a >>= deserialize
18261827 where deserialize = parseMaybe parseJSON
18271828
18281829instance BucketAggregation TermsResult where