[Haskell-beginners] better way: contains one of a string from list in a string
Miro Karpis
miroslav.karpis at gmail.com
Sun Mar 20 07:02:07 UTC 2016
Hi,
I needed a function that returns True/False if a list of strings are in a
given string. I made one function below (works fine),..but I was wondering
whether there is a shorter way?
-- |Returns True if one of given strings are contained in given string
contains :: [String] -> String -> Bool
contains elements seach_elem
| trueListCount == 0 = False
| otherwise = True
where
isInStringList = [isInfixOf elem seach_elem | elem <- elements]
onlyTrueList = [elem | elem <- isInStringList, elem == True]
trueListCount = length onlyTrueList
Cheers,
-m
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160320/85498e7c/attachment.html>
More information about the Beginners
mailing list