From 2a36ac0d6288efe658fd464decfdf96abce173b5 Mon Sep 17 00:00:00 2001 From: Mykola Orliuk Date: Tue, 19 Nov 2019 20:43:19 +0100 Subject: [PATCH] ;lib: fix doctest for RawOptions --- hledger-lib/Hledger/Data/RawOptions.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Data/RawOptions.hs b/hledger-lib/Hledger/Data/RawOptions.hs index 64391cdcf..0e123bd6a 100644 --- a/hledger-lib/Hledger/Data/RawOptions.hs +++ b/hledger-lib/Hledger/Data/RawOptions.hs @@ -55,15 +55,19 @@ inRawOpts name = isJust . lookup name . unRawOpts boolopt :: String -> RawOpts -> Bool boolopt = inRawOpts --- | Get latests successfully parsed flag +-- | Get latests successfully parsed flag. +-- +-- Expected to be used for exclusive choice flags like "--json" vs "--csv". -- -- >>> choiceopt Just (RawOpts [("a",""), ("b",""), ("c","")]) -- Just "c" -- >>> choiceopt (const Nothing) (RawOpts [("a","")]) -- Nothing --- >>> choiceopt (listToMaybe . filter (`elem` ["a","b"])) (RawOpts [("a",""), ("b",""), ("c","")]) --- Just "b" -choiceopt :: (String -> Maybe a) -> RawOpts -> Maybe a +-- >>> choiceopt readMay (RawOpts [("LT",""),("EQ",""),("Neither","")]) :: Maybe Ordering +-- Just EQ +choiceopt :: (String -> Maybe a) -- ^ "parser" that returns 'Just' value for valid choice + -> RawOpts -- ^ actual options where to look for flag + -> Maybe a -- ^ exclusive choice among those returned as 'Just' from "parser" choiceopt f = lastMay . collectopts (f . fst) -- | Collects processed and filtered list of options preserving their order