gdritter repos s-cargot / b5c90c8
Added docs for WellFormed cons/uncons Getty Ritter 8 years ago
1 changed file(s) with 11 addition(s) and 0 deletion(s). Collapse all Expand all
3030 import Control.Applicative ((<$>), (<*>), pure)
3131 import Data.SCargot.Repr as R
3232
33 -- | Produce the head and tail of the s-expression (if possible).
34 --
35 -- >>> uncons (L [A "el", A "eph", A "ant"])
36 -- Just (WFSAtom "el",WFSList [WFSAtom "eph",WFSAtom "ant"])
3337 uncons :: WellFormedSExpr a -> Maybe (WellFormedSExpr a, WellFormedSExpr a)
3438 uncons R.WFSAtom {} = Nothing
3539 uncons (R.WFSList (x:xs)) = Just (x, R.WFSList xs)
3640
41 -- | Combine the two-expressions into a new one. This will return
42 -- @Nothing@ if the resulting s-expression is not well-formed.
43 --
44 -- >>> cons (A "el") (L [A "eph", A "ant"])
45 -- Just (WFSList [WFSAtom "el",WFSAtom "eph",WFSAtom "ant"])
46 -- >>> cons (A "pachy") (A "derm"))
47 -- Nothing
3748 cons :: WellFormedSExpr a -> WellFormedSExpr a -> Maybe (WellFormedSExpr a)
3849 cons _ (R.WFSAtom {}) = Nothing
3950 cons x (R.WFSList xs) = Just (R.WFSList (x:xs))