Count occurrences of a substring: Difference between revisions
Content added Content deleted
Line 1,398: | Line 1,398: | ||
Alternatively, in a language built around currying, it might make more sense to reverse the suggested order of arguments. |
Alternatively, in a language built around currying, it might make more sense to reverse the suggested order of arguments. |
||
<lang haskell> |
<lang haskell>{-# LANGUAGE OverloadedStrings #-} |
||
import Data.Text hiding (length) |
|||
⚫ | |||
⚫ | |||
where |
|||
⚫ | |||
--------- COUNT OF SUBSTRING INSTANCES IN A STRING ------- |
|||
⚫ | |||
⚫ | |||
length |
|||
⚫ | |||
--------------------------- TEST ------------------------- |
|||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
print $ |
|||
print $ countAll "ab" <$> ["ababababab", "abelian absurdity", "babel kebab"]</lang> |
|||
countAll "ab" |
|||
<$> [ "ababababab", |
|||
"abelian absurdity", |
|||
"babel kebab" |
|||
]</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>[5,2,2]</pre> |
<pre>[5,2,2]</pre> |