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
55 , fromList
66 , toList
77 , singleton
8+ , cons
9+ , snoc
810 , head
911 , last
1012 , tail
1113 , init
1214 , uncons
15+ , unsnoc
1316 , length
1417 , concatMap
1518 , appendFoldable
@@ -47,6 +50,12 @@ toList (NonEmptyList (x :| xs)) = x : xs
4750singleton :: forall a . a -> NonEmptyList a
4851singleton = NonEmptyList <<< NE .singleton
4952
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+
5059head :: forall a . NonEmptyList a -> a
5160head (NonEmptyList (x :| _)) = x
5261
@@ -62,6 +71,11 @@ init (NonEmptyList (x :| xs)) = maybe L.Nil (x : _) (L.init xs)
6271uncons :: forall a . NonEmptyList a -> { head :: a , tail :: L.List a }
6372uncons (NonEmptyList (x :| xs)) = { head: x, tail: xs }
6473
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+
6579length :: forall a . NonEmptyList a -> Int
6680length (NonEmptyList (x :| xs)) = 1 + L .length xs
6781
You can’t perform that action at this time.
0 commit comments