File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 18
18
],
19
19
"dependencies" : {
20
20
"purescript-partial" : " ^1.2.0" ,
21
- "purescript-tuples" : " ^4.0.0"
21
+ "purescript-tuples" : " ^4.0.0" ,
22
+ "purescript-control" : " ^3.3.1"
22
23
},
23
24
"devDependencies" : {
24
25
"purescript-assert" : " ^3.0.0" ,
Original file line number Diff line number Diff line change @@ -10,12 +10,14 @@ module Data.Unfoldable
10
10
, replicateA
11
11
, none
12
12
, singleton
13
+ , iterate
13
14
, range
14
15
, fromMaybe
15
16
) where
16
17
17
18
import Prelude
18
19
20
+ import Control.Lazy (class Lazy )
19
21
import Data.Maybe (Maybe (..), isNothing , fromJust )
20
22
import Data.Traversable (class Traversable , sequence )
21
23
import Data.Tuple (Tuple (..), fst , snd )
@@ -89,6 +91,15 @@ none = unfoldr (const Nothing) unit
89
91
singleton :: forall f a . Unfoldable f => a -> f a
90
92
singleton = replicate 1
91
93
94
+ -- | Lazily produce an Unfoldable structure by iterating a function.
95
+ -- | For example, to lazily produce integers starting with zero:
96
+ -- |
97
+ -- | ~~~ purescript
98
+ -- | nats = iterate add zero
99
+ -- | ~~~
100
+ iterate :: forall f a . Unfoldable f => Lazy (f a ) => (a -> a ) -> a -> f a
101
+ iterate f = unfoldr (\x -> Just (Tuple x (f x)))
102
+
92
103
-- | Create an Unfoldable containing a range of values, with both endpoints.
93
104
range :: forall f . Unfoldable f => Int -> Int -> f Int
94
105
range start end =
You can’t perform that action at this time.
0 commit comments