@@ -7,7 +7,7 @@ module Data.List.NonEmpty
77 , singleton
88 , length
99 , cons
10- , cons'
10+ , (:||), cons'
1111 , snoc
1212 , snoc'
1313 , head
@@ -93,7 +93,7 @@ wrappedOperation
9393 -> NonEmptyList b
9494wrappedOperation name f (NonEmptyList (x :| xs)) =
9595 case f (x : xs) of
96- x' : xs' -> NonEmptyList ( x' :| xs')
96+ x' : xs' -> x' :|| xs'
9797 L.Nil -> unsafeCrashWith (" Impossible: empty list in NonEmptyList " <> name)
9898
9999-- | Like `wrappedOperation`, but for functions that operate on 2 lists.
@@ -106,7 +106,7 @@ wrappedOperation2
106106 -> NonEmptyList c
107107wrappedOperation2 name f (NonEmptyList (x :| xs)) (NonEmptyList (y :| ys)) =
108108 case f (x : xs) (y : ys) of
109- x' : xs' -> NonEmptyList ( x' :| xs')
109+ x' : xs' -> x' :|| xs'
110110 L.Nil -> unsafeCrashWith (" Impossible: empty list in NonEmptyList " <> name)
111111
112112-- | Lifts a function that operates on a list to work on a NEL. This does not
@@ -123,7 +123,7 @@ fromFoldable = fromList <<< L.fromFoldable
123123
124124fromList :: forall a . L.List a -> Maybe (NonEmptyList a )
125125fromList L.Nil = Nothing
126- fromList (x : xs) = Just (NonEmptyList ( x :| xs) )
126+ fromList (x : xs) = Just (x :|| xs)
127127
128128toList :: NonEmptyList ~> L.List
129129toList (NonEmptyList (x :| xs)) = x : xs
@@ -132,16 +132,18 @@ singleton :: forall a. a -> NonEmptyList a
132132singleton = NonEmptyList <<< NE .singleton
133133
134134cons :: forall a . a -> NonEmptyList a -> NonEmptyList a
135- cons y (NonEmptyList (x :| xs)) = NonEmptyList ( y :| x : xs)
135+ cons y (NonEmptyList (x :| xs)) = y :|| x : xs
136136
137137cons' :: forall a . a -> L.List a -> NonEmptyList a
138138cons' x xs = NonEmptyList (x :| xs)
139139
140+ infixr 5 cons' as :||
141+
140142snoc :: forall a . NonEmptyList a -> a -> NonEmptyList a
141- snoc (NonEmptyList (x :| xs)) y = NonEmptyList ( x :| L .snoc xs y)
143+ snoc (NonEmptyList (x :| xs)) y = x :|| L .snoc xs y
142144
143145snoc' :: forall a . L.List a -> a -> NonEmptyList a
144- snoc' (x : xs) y = NonEmptyList ( x :| L .snoc xs y)
146+ snoc' (x : xs) y = x :|| L .snoc xs y
145147snoc' L.Nil y = singleton y
146148
147149head :: forall a . NonEmptyList a -> a
@@ -195,18 +197,18 @@ findLastIndex f (NonEmptyList (x :| xs)) =
195197
196198insertAt :: forall a . Int -> a -> NonEmptyList a -> Maybe (NonEmptyList a )
197199insertAt i a (NonEmptyList (x :| xs))
198- | i == 0 = Just (NonEmptyList ( a :| x : xs) )
200+ | i == 0 = Just (a :|| x : xs)
199201 | otherwise = NonEmptyList <<< (x :| _) <$> L .insertAt (i - 1 ) a xs
200202
201203updateAt :: forall a . Int -> a -> NonEmptyList a -> Maybe (NonEmptyList a )
202204updateAt i a (NonEmptyList (x :| xs))
203- | i == 0 = Just (NonEmptyList ( a :| xs) )
204- | otherwise = NonEmptyList <<< (x :| _) <$> L .updateAt (i - 1 ) a xs
205+ | i == 0 = Just (a :|| xs)
206+ | otherwise = (x :| | _) <$> L .updateAt (i - 1 ) a xs
205207
206208modifyAt :: forall a . Int -> (a -> a ) -> NonEmptyList a -> Maybe (NonEmptyList a )
207209modifyAt i f (NonEmptyList (x :| xs))
208- | i == 0 = Just (NonEmptyList ( f x :| xs) )
209- | otherwise = NonEmptyList <<< (x :| _) <$> L .modifyAt (i - 1 ) f xs
210+ | i == 0 = Just (f x :|| xs)
211+ | otherwise = (x :| | _) <$> L .modifyAt (i - 1 ) f xs
210212
211213reverse :: forall a . NonEmptyList a -> NonEmptyList a
212214reverse = wrappedOperation " reverse" L .reverse
@@ -231,7 +233,7 @@ concatMap = flip bind
231233
232234appendFoldable :: forall t a . Foldable t => NonEmptyList a -> t a -> NonEmptyList a
233235appendFoldable (NonEmptyList (x :| xs)) ys =
234- NonEmptyList ( x :| (xs <> L .fromFoldable ys) )
236+ x :|| (xs <> L .fromFoldable ys)
235237
236238-- | Apply a function to each element and its index in a list starting at 0.
237239-- |
@@ -298,7 +300,7 @@ intersectBy = wrappedOperation2 "intersectBy" <<< L.intersectBy
298300
299301zipWith :: forall a b c . (a -> b -> c ) -> NonEmptyList a -> NonEmptyList b -> NonEmptyList c
300302zipWith f (NonEmptyList (x :| xs)) (NonEmptyList (y :| ys)) =
301- NonEmptyList ( f x y :| L .zipWith f xs ys)
303+ f x y :|| L .zipWith f xs ys
302304
303305zipWithA :: forall m a b c . Applicative m => (a -> b -> m c ) -> NonEmptyList a -> NonEmptyList b -> m (NonEmptyList c )
304306zipWithA f xs ys = sequence1 (zipWith f xs ys)
0 commit comments