File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
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,15 +10,16 @@ module Data.Unfoldable
10
10
, replicateA
11
11
, none
12
12
, singleton
13
+ , nats
13
14
, fromMaybe
14
15
) where
15
16
16
17
import Prelude
17
18
19
+ import Control.Lazy (class Lazy )
18
20
import Data.Maybe (Maybe (..), isNothing , fromJust )
19
21
import Data.Traversable (class Traversable , sequence )
20
22
import Data.Tuple (Tuple (..), fst , snd )
21
-
22
23
import Partial.Unsafe (unsafePartial )
23
24
24
25
-- | This class identifies data structures which can be _unfolded_,
@@ -88,6 +89,13 @@ none = unfoldr (const Nothing) unit
88
89
singleton :: forall f a . Unfoldable f => a -> f a
89
90
singleton = replicate 1
90
91
92
+ -- | Produce a Lazy Unfoldable structure representing the natural numbers.
93
+ nats :: forall f a . Unfoldable f => Semiring a => Lazy (f a ) => f a
94
+ nats = unfoldr increment zero
95
+ where
96
+ increment :: a -> Maybe (Tuple a a )
97
+ increment a = Just (Tuple a $ add one a)
98
+
91
99
-- | Convert a Maybe to any Unfoldable like lists and arrays.
92
100
fromMaybe :: forall f a . Unfoldable f => Maybe a -> f a
93
101
fromMaybe = unfoldr (\b -> flip Tuple Nothing <$> b)
You can’t perform that action at this time.
0 commit comments