I have the following 2 functions:
import qualified Data.Text as T
noneOnEmptyA :: T.Text -> T.Text
noneOnEmptyA txt | T.null txt = "None."
| otherwise = txt
noneOnEmptyB :: [T.Text] -> [T.Text]
noneOnEmptyB txts | null txts = ["None."]
| otherwise = txts
Is it possible to write a single function that 1) accomplishes what noneOnEmptyA
does, and 2) can be lifted such that it accomplishes what noneOnEmptyB
does? The crux of the problem seems to be that noneOnEmptyA
checks for empty text, while noneOnEmptyB
checks for an empty list; however, noneOnEmptyA
lifted so as to operate on lists (as in fmap noneOnEmptyA
returning type [T.Text]
) checks for empty text inside the list, rather than checking whether or not the list itself is empty.