File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ module Data.List.Lazy
16
16
, (..), range
17
17
, replicate
18
18
, replicateM
19
- -- , some
20
- -- , many
19
+ , some
20
+ , many
21
21
, repeat
22
22
, iterate
23
23
, cycle
@@ -91,6 +91,8 @@ module Data.List.Lazy
91
91
92
92
import Prelude
93
93
94
+ import Control.Alt ((<|>))
95
+ import Control.Alternative (class Alternative )
94
96
import Control.Lazy as Z
95
97
96
98
import Data.Foldable (class Foldable , foldr , any , foldl )
@@ -160,6 +162,21 @@ replicateM n m
160
162
as <- replicateM (n - one) m
161
163
pure (cons a as)
162
164
165
+ -- | Attempt a computation multiple times, requiring at least one success.
166
+ -- |
167
+ -- | The `Lazy` constraint is used to generate the result lazily, to ensure
168
+ -- | termination.
169
+ some :: forall f a . Alternative f => Z.Lazy (f (List a )) => f a -> f (List a )
170
+ some v = cons <$> v <*> Z .defer (\_ -> many v)
171
+
172
+ -- | Attempt a computation multiple times, returning as many successful results
173
+ -- | as possible (possibly zero).
174
+ -- |
175
+ -- | The `Lazy` constraint is used to generate the result lazily, to ensure
176
+ -- | termination.
177
+ many :: forall f a . Alternative f => Z.Lazy (f (List a )) => f a -> f (List a )
178
+ many v = some v <|> pure nil
179
+
163
180
-- | Create a list by repeating an element
164
181
repeat :: forall a . a -> List a
165
182
repeat x = Z .fix \xs -> cons x xs
You can’t perform that action at this time.
0 commit comments