We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
foldl
foldr
1 parent f75324b commit e78bef5Copy full SHA for e78bef5
1 file changed
source_md/modules.md
@@ -336,9 +336,13 @@ Let's use a fold to implement searching a list for a sublist.
336
337
```{.haskell:hs}
338
search :: (Eq a) => [a] -> [a] -> Bool
339
-search needle haystack =
340
- let nlen = length needle
341
- in foldl (\acc x -> if take nlen x == needle then True else acc) False (tails haystack)
+search needle haystack = foldr step False (tails haystack)
+ where
+ step segment continue =
342
+ if take nlen segment == needle
343
+ then True
344
+ else continue
345
+ nlen = length needle
346
```
347
348
First we call `tails` with the list in which we're searching.
0 commit comments