I am using haskell and the following:
convertToBasis :: [String] -> Maybe [Basis] convertToBasis [] = Nothing convertToBasis (h:t) = basis : convertToBasis t where basis = toCandidateBasis h Returns a type of [Maybe Basis] I want a type of Maybe [Basis] toCandidateBasis is shown below:
toCandidateBasis :: String -> Maybe Basis toCandidateBasis myStr = if not $ has7UniqueLetters myStr [] then Nothing else Just (dedupAndSort myStr) The function returns nothing if a String does not have 7 unique characters otherwise it removes duplicates and sorts the String alphabetically and return that result. Now the return type of the function is Maybe Basis. Hence when I when I get a list of strings and want to convert them to their respective candidate basises one by one, it will concat all the maybes and return me a type of:
[Maybe Basis] But I want a type of
Maybe [Basis] It should return Nothing only when the given Basis array is empty otherwise return some result. How do I do this?
Just []is impossible, then there's no point in returning a Maybe at all. "non-empty list or nothing" conveys the same values as "possibly-empty list".filter (not . null).