Module
Data.NonEmpty
- Package
- purescript-nonempty
- Repository
- purescript/purescript-nonempty
This module defines a generic non-empty data structure, which adds an additional element to any container type.
#NonEmpty Source
data NonEmpty f a
A non-empty container of elements of type a.
import Data.NonEmpty
nonEmptyArray :: NonEmpty Array Int
nonEmptyArray = NonEmpty 1 [2,3]
import Data.List(List(..), (:))
nonEmptyList :: NonEmpty List Int
nonEmptyList = NonEmpty 1 (2 : 3 : Nil)
Constructors
NonEmpty a (f a)
Instances
(Show a, Show (f a)) => Show (NonEmpty f a)
(Eq1 f, Eq a) => Eq (NonEmpty f a)
(Eq1 f) => Eq1 (NonEmpty f)
(Ord1 f, Ord a) => Ord (NonEmpty f a)
(Ord1 f) => Ord1 (NonEmpty f)
(Functor f) => Functor (NonEmpty f)
(FunctorWithIndex i f) => FunctorWithIndex (Maybe i) (NonEmpty f)
(Foldable f) => Foldable (NonEmpty f)
(FoldableWithIndex i f) => FoldableWithIndex (Maybe i) (NonEmpty f)
(Traversable f) => Traversable (NonEmpty f)
(TraversableWithIndex i f) => TraversableWithIndex (Maybe i) (NonEmpty f)
(Foldable f) => Foldable1 (NonEmpty f)
(Unfoldable f) => Unfoldable1 (NonEmpty f)
#(:|) Source
Operator alias for Data.NonEmpty.NonEmpty (right-associative / precedence 5)
An infix synonym for NonEmpty
.
nonEmptyArray :: NonEmpty Array Int
nonEmptyArray = 1 :| [2,3]
nonEmptyList :: NonEmpty List Int
nonEmptyList = 1 :| 2 : 3 : Nil
#foldl1 Source
foldl1 :: forall f a. Foldable f => Warn (Text "\'Data.NonEmpty.foldl1\' is deprecated, use \'Data.Semigroup.Foldable.foldl1\' instead") => (a -> a -> a) -> NonEmpty f a -> a
Fold a non-empty structure, collecting results using a binary operation.
Deprecated, use 'Data.Semigroup.Foldable.foldl1' instead
foldl1 (+) (1 :| [2, 3]) == 6
#fromNonEmpty Source
fromNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r
Apply a function that takes the first
element and remaining elements
as arguments to a non-empty container.
For example, return the remaining elements multiplied by the first element:
fromNonEmpty (\x xs -> map (_ * x) xs) (3 :| [2, 1]) == [6, 3]
#oneOf Source
oneOf :: forall f a. Alternative f => NonEmpty f a -> f a
Returns the alt
(<|>
) result of:
- The first element lifted to the container of the remaining elements.
- The remaining elements.
import Data.Maybe(Maybe(..))
oneOf (1 :| Nothing) == Just 1
oneOf (1 :| Just 2) == Just 1
oneOf (1 :| [2, 3]) == [1,2,3]
- Modules
- Data.
NonEmpty