Skip to content

Commit 3566228

Browse files
authored
Merge pull request #153 from garyb/nel-cons-construction
Add cons/snoc variants for creating NEL from item & list
2 parents 3d864d1 + bd6ab25 commit 3566228

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Data/List/NonEmpty.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module Data.List.NonEmpty
77
, singleton
88
, length
99
, cons
10+
, cons'
1011
, snoc
12+
, snoc'
1113
, head
1214
, last
1315
, tail
@@ -128,9 +130,16 @@ singleton = NonEmptyList <<< NE.singleton
128130
cons :: forall a. a -> NonEmptyList a -> NonEmptyList a
129131
cons y (NonEmptyList (x :| xs)) = NonEmptyList (y :| x : xs)
130132

133+
cons' :: forall a. a -> L.List a -> NonEmptyList a
134+
cons' x xs = NonEmptyList (x :| xs)
135+
131136
snoc :: forall a. NonEmptyList a -> a -> NonEmptyList a
132137
snoc (NonEmptyList (x :| xs)) y = NonEmptyList (x :| L.snoc xs y)
133138

139+
snoc' :: forall a. L.List a -> a -> NonEmptyList a
140+
snoc' (x : xs) y = NonEmptyList (x :| L.snoc xs y)
141+
snoc' L.Nil y = singleton y
142+
134143
head :: forall a. NonEmptyList a -> a
135144
head (NonEmptyList (x :| _)) = x
136145

0 commit comments

Comments
 (0)