File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,14 @@ module Data.List.NonEmpty
5
5
, fromList
6
6
, toList
7
7
, singleton
8
+ , cons
9
+ , snoc
8
10
, head
9
11
, last
10
12
, tail
11
13
, init
12
14
, uncons
15
+ , unsnoc
13
16
, length
14
17
, concatMap
15
18
, appendFoldable
@@ -47,6 +50,12 @@ toList (NonEmptyList (x :| xs)) = x : xs
47
50
singleton :: forall a . a -> NonEmptyList a
48
51
singleton = NonEmptyList <<< NE .singleton
49
52
53
+ cons :: forall a . a -> NonEmptyList a -> NonEmptyList a
54
+ cons y (NonEmptyList (x :| xs)) = NonEmptyList (y :| x : xs)
55
+
56
+ snoc :: forall a . NonEmptyList a -> a -> NonEmptyList a
57
+ snoc (NonEmptyList (x :| xs)) y = NonEmptyList (x :| L .snoc xs y)
58
+
50
59
head :: forall a . NonEmptyList a -> a
51
60
head (NonEmptyList (x :| _)) = x
52
61
@@ -62,6 +71,11 @@ init (NonEmptyList (x :| xs)) = maybe L.Nil (x : _) (L.init xs)
62
71
uncons :: forall a . NonEmptyList a -> { head :: a , tail :: L.List a }
63
72
uncons (NonEmptyList (x :| xs)) = { head: x, tail: xs }
64
73
74
+ unsnoc :: forall a . NonEmptyList a -> { init :: L.List a , last :: a }
75
+ unsnoc (NonEmptyList (x :| xs)) = case L .unsnoc xs of
76
+ Nothing -> { init: L.Nil , last: x }
77
+ Just un -> { init: x : un.init, last: un.last }
78
+
65
79
length :: forall a . NonEmptyList a -> Int
66
80
length (NonEmptyList (x :| xs)) = 1 + L .length xs
67
81
You can’t perform that action at this time.
0 commit comments