File tree 3 files changed +9
-0
lines changed
3 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
7
7
Breaking changes:
8
8
9
9
New features:
10
+ - Added ` cons ` for ` Lazy.NonEmptyList ` (#143 by @matthewleon )
10
11
11
12
Bugfixes:
12
13
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ module Data.List.Lazy.NonEmpty
11
11
, last
12
12
, tail
13
13
, init
14
+ , cons
14
15
, uncons
15
16
, length
16
17
, concatMap
@@ -69,6 +70,10 @@ init (NonEmptyList nel) =
69
70
of x :| xs ->
70
71
maybe L .nil (x : _) (L .init xs)
71
72
73
+ cons :: forall a . a -> NonEmptyList a -> NonEmptyList a
74
+ cons y (NonEmptyList nel) =
75
+ NonEmptyList (defer \_ -> case force nel of x :| xs -> y :| x : xs)
76
+
72
77
uncons :: forall a . NonEmptyList a -> { head :: a , tail :: L.List a }
73
78
uncons (NonEmptyList nel) = case force nel of x :| xs -> { head: x, tail: xs }
74
79
Original file line number Diff line number Diff line change @@ -441,6 +441,9 @@ testListLazy = do
441
441
log " transpose (singleton nil) == nil"
442
442
assert $ transpose (singleton nil) == (nil :: List (List Int ))
443
443
444
+ log " NonEmptyList cons should add an element"
445
+ assert $ NEL .toList (NEL .cons 0 (NEL .singleton 1 )) == fromFoldable [0 , 1 ]
446
+
444
447
log " unfoldr should maintain order"
445
448
assert $ (1 ..5 ) == unfoldr step 1
446
449
You can’t perform that action at this time.
0 commit comments