Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions docs/Data/NonEmpty.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ nonEmptyList = 0 :| empty

##### Instances
``` purescript
instance showNonEmpty :: (Show a, Show (f a)) => Show (NonEmpty f a)
instance eqNonEmpty :: (Eq a, Eq (f a)) => Eq (NonEmpty f a)
instance ordNonEmpty :: (Ord a, Ord (f a)) => Ord (NonEmpty f a)
instance functorNonEmpty :: (Functor f) => Functor (NonEmpty f)
instance foldableNonEmpty :: (Foldable f) => Foldable (NonEmpty f)
instance traversableNonEmpty :: (Traversable f) => Traversable (NonEmpty f)
(Show a, Show (f a)) => Show (NonEmpty f a)
(Eq a, Eq (f a)) => Eq (NonEmpty f a)
(Ord a, Ord (f a)) => Ord (NonEmpty f a)
(Functor f) => Functor (NonEmpty f)
(Foldable f) => Foldable (NonEmpty f)
(Traversable f) => Traversable (NonEmpty f)
```

#### `singleton`
Expand All @@ -50,7 +50,7 @@ An infix synonym for `NonEmpty`.
#### `foldl1`

``` purescript
foldl1 :: forall f a s. (Foldable f) => (a -> a -> a) -> NonEmpty f a -> a
foldl1 :: forall f a. (Foldable f) => (a -> a -> a) -> NonEmpty f a -> a
```

Fold a non-empty structure, collecting results using a binary operation.
Expand Down Expand Up @@ -83,4 +83,20 @@ fromNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r
oneOf :: forall f a. (Alternative f) => NonEmpty f a -> f a
```

#### `head`

``` purescript
head :: forall f a. NonEmpty f a -> a
```

Get the 'first' element of a non-empty container.

#### `tail`

``` purescript
tail :: forall f a. NonEmpty f a -> f a
```

Get everything but the 'first' element of a non-empty container.


10 changes: 10 additions & 0 deletions src/Data/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Data.NonEmpty
, fold1
, fromNonEmpty
, oneOf
, head
, tail
) where

import Prelude
Expand Down Expand Up @@ -59,6 +61,14 @@ fromNonEmpty f (NonEmpty a fa) = a `f` fa
oneOf :: forall f a. (Alternative f) => NonEmpty f a -> f a
oneOf (NonEmpty a fa) = pure a <|> fa

-- | Get the 'first' element of a non-empty container.
head :: forall f a. NonEmpty f a -> a
head (NonEmpty x _) = x

-- | Get everything but the 'first' element of a non-empty container.
tail :: forall f a. NonEmpty f a -> f a
tail (NonEmpty _ xs) = xs

instance showNonEmpty :: (Show a, Show (f a)) => Show (NonEmpty f a) where
show (NonEmpty a fa) = "(NonEmpty " ++ show a ++ " " ++ show fa ++ ")"

Expand Down