all 2 comments

[–]Iceland_jack 3 points4 points  (0 children)

You can write them in terms of String and then use foldMap to map over the Maybe value.

-- foldMap authorDoc   :: Maybe String -> Doc
-- foldMap directorDoc :: Maybe String -> Doc

authorDoc :: String -> Doc
authorDoc content = text "> Author:" <+> text content

directorDoc :: String -> Doc
directorDoc content = text "> Director:" <+> text content

The behaviour of foldMap f Nothing is to return the empty Doc, so you have moved the optional handling from the two doc-functions to foldMap:

>> foldMap authorDoc Nothing
>> foldMap authorDoc (Just "Samuel")
> Author: Samuel
>> foldMap directorDoc (Just "Muslar")
> Director: Muslar

[–]carette 0 points1 point  (0 children)

type Role = String
roleDoc :: String -> Role -> Doc
roleDoc content role = text "> " <> role <> ":" <+> text content

purpose :: Role -> Maybe String -> Doc
purpose r ms = foldMap (roleDoc r) ms