@@ -21,20 +21,20 @@ import Partial.Unsafe (unsafePartial)
21
21
-- |
22
22
-- | Note that, in order to provide an `Unfoldable1 t` instance, `t` need not
23
23
-- | be a type which is guaranteed to be non-empty. For example, the fact that
24
- -- | arrays can be empty does not prevent us from providing an `Unfoldable1
25
- -- | Array` instance. However, the result of `unfoldr1` should always be
26
- -- | non-empty.
24
+ -- | lists can be empty does not prevent us from providing an
25
+ -- | `Unfoldable1 List` instance. However, the result of `unfoldr1` should
26
+ -- | always be non-empty.
27
27
-- |
28
28
-- | Every type which has an `Unfoldable` instance can be given an
29
29
-- | `Unfoldable1` instance (and, in fact, is required to, because
30
30
-- | `Unfoldable1` is a superclass of `Unfoldable`). However, there are types
31
31
-- | which have `Unfoldable1` instances but cannot have `Unfoldable` instances.
32
32
-- | In particular, types which are guaranteed to be non-empty, such as
33
- -- | `NonEmptyArray `, cannot be given `Unfoldable` instances.
33
+ -- | `NonEmptyList `, cannot be given `Unfoldable` instances.
34
34
-- |
35
35
-- | The utility of this class, then, is that it provides an `Unfoldable`-like
36
36
-- | interface while still permitting instances for guaranteed-non-empty types
37
- -- | like `NonEmptyArray `.
37
+ -- | like `NonEmptyList `.
38
38
class Unfoldable1 t where
39
39
unfoldr1 :: forall a b . (b -> Tuple a (Maybe b )) -> b -> t a
40
40
@@ -52,11 +52,11 @@ foreign import unfoldr1ArrayImpl
52
52
-> Array a
53
53
54
54
-- | Replicate a value `n` times. At least one value will be produced, so values
55
- -- | `n < 1 ` less than one will be ignored .
55
+ -- | `n` less than 1 will be treated as 1 .
56
56
-- |
57
57
-- | ``` purescript
58
- -- | replicate1 0 "foo" == NEL.singleton "foo" :: NEL.NonEmptyList String
59
- -- | replicate1 2 "foo" == NEL.cons "foo" (NEL.singleton "foo") :: NEL.NonEmptyList String
58
+ -- | replicate1 2 "foo" == ( NEL.cons "foo" (NEL. singleton "foo") :: NEL.NonEmptyList String)
59
+ -- | replicate1 0 "foo" == (NEL.singleton "foo" :: NEL.NonEmptyList String)
60
60
-- | ```
61
61
replicate1 :: forall f a . Unfoldable1 f => Int -> a -> f a
62
62
replicate1 n v = unfoldr1 step (n - 1 )
@@ -66,8 +66,15 @@ replicate1 n v = unfoldr1 step (n - 1)
66
66
| i <= 0 = Tuple v Nothing
67
67
| otherwise = Tuple v (Just (i - 1 ))
68
68
69
- -- | Perform an `Apply` action `n` times (at least once, so values `n < 1`
70
- -- | less than one will be ignored), and accumulate the results.
69
+ -- | Perform an `Apply` action `n` times (at least once, so values `n` less
70
+ -- | than 1 will be treated as 1), and accumulate the results.
71
+ -- |
72
+ -- | ``` purescript
73
+ -- | > replicate1A 2 (randomInt 1 10) :: Effect (NEL.NonEmptyList Int)
74
+ -- | (NonEmptyList (NonEmpty 8 (2 : Nil)))
75
+ -- | > replicate1A 0 (randomInt 1 10) :: Effect (NEL.NonEmptyList Int)
76
+ -- | (NonEmptyList (NonEmpty 4 Nil))
77
+ -- | ```
71
78
replicate1A
72
79
:: forall m f a
73
80
. Apply m
@@ -81,7 +88,7 @@ replicate1A n m = sequence1 (replicate1 n m)
81
88
-- | Contain a single value. For example:
82
89
-- |
83
90
-- | ``` purescript
84
- -- | singleton "foo" == NEL.singleton "foo" :: NEL.NonEmptyList String
91
+ -- | singleton "foo" == ( NEL.singleton "foo" :: NEL.NonEmptyList String)
85
92
-- | ```
86
93
singleton :: forall f a . Unfoldable1 f => a -> f a
87
94
singleton = replicate1 1
@@ -90,9 +97,9 @@ singleton = replicate1 1
90
97
-- | endpoints.
91
98
-- |
92
99
-- | ``` purescript
93
- -- | range 0 0 "foo" == NEL.singleton 0 :: NEL.NonEmptyList Int
94
- -- | range 1 2 "foo" == NEL.cons 1 (NEL.singleton 2) :: NEL.NonEmptyList Int
95
- -- | range 2 0 "foo" == NEL.cons 2 (NEL.cons 1 (NEL.singleton 0)) :: NEL.NonEmptyList Int
100
+ -- | range 0 0 == ( NEL.singleton 0 :: NEL.NonEmptyList Int)
101
+ -- | range 1 2 == ( NEL.cons 1 (NEL.singleton 2) :: NEL.NonEmptyList Int)
102
+ -- | range 2 0 == ( NEL.cons 2 (NEL.cons 1 (NEL.singleton 0)) :: NEL.NonEmptyList Int)
96
103
-- | ```
97
104
range :: forall f . Unfoldable1 f => Int -> Int -> f Int
98
105
range start end =
0 commit comments