+-- | (Un)pickle a 'Int', allowing for a value of \"TBA\" (which gets
+-- translated to 'Nothing').
+--
+-- /Examples/:
+--
+-- A failed parse will return 'Nothing':
+--
+-- >>> let tn = text_node "YO"
+-- >>> unpickleDoc xp_tba_int tn
+-- Just Nothing
+--
+-- And so will parsing a \"TBA\":
+--
+-- >>> let tn = text_node "TBA"
+-- >>> unpickleDoc xp_tba_int tn
+-- Just Nothing
+--
+-- But re-pickling 'Nothing' gives only \"TBA\":
+--
+-- >>> pickleDoc xp_tba_int Nothing
+-- NTree (XTag "/" []) [NTree (XText "TBA") []]
+--
+-- A normal integer is also parsed successfully, of course:
+--
+-- >>> let tn = text_node "110"
+-- >>> unpickleDoc xp_tba_int tn
+-- Just (Just 110)
+--
+xp_tba_int :: PU (Maybe Int)
+xp_tba_int =
+ (to_int, from_int) `xpWrap` xpText
+ where
+ to_int :: String -> Maybe Int
+ to_int = readMaybe
+
+ from_int :: Maybe Int -> String
+ from_int Nothing = "TBA"
+ from_int (Just t) = show t
+
+