Copyright | (c) 2011-2015 Edward Kmett (c) 2018 Kowainik |
---|---|
License | MIT |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Safe Haskell | Safe |
Language | Haskell2010 |
Documentation
class Foldable f => Foldable1 f where Source #
The class of foldable data structures that cannot be empty.
foldMap1 :: Semigroup m => (a -> m) -> f a -> m Source #
Map each element of the non-empty structure to a semigroup, and combine the results.
>>>
foldMap1 SG.Sum (1 :| [2, 3, 4])
Sum {getSum = 10}
fold1 :: Semigroup m => f m -> m Source #
Combine the elements of a non-empty structure using a semigroup.
>>>
fold1 (1 :| [2, 3, 4 :: SG.Sum Int])
Sum {getSum = 10}>>>
fold1 (4 :| [5, 10 :: SG.Product Int])
Product {getProduct = 200}
toNonEmpty :: f a -> NonEmpty a Source #
Convert a non-empty data structre to a NonEmpty list.
>>>
toNonEmpty (Identity 2)
2 :| []
The first element of a non-empty data structure.
>>>
head1 (1 :| [2, 3, 4])
1
The last element of a non-empty data structure.
>>>
last1 (1 :| [2, 3, 4])
4
maximum1 :: Ord a => f a -> a Source #
The largest element of a non-empty data structure.
>>>
maximum1 (32 :| [64, 8, 128, 16])
128
minimum1 :: Ord a => f a -> a Source #
The smallest elemenet of a non-empty data structure.
>>>
minimum1 (32 :| [64, 8, 128, 16])
8
Instances
Foldable1 Identity Source # | |
Defined in Relude.Extra.Foldable1 | |
Foldable1 NonEmpty Source # | |
Defined in Relude.Extra.Foldable1 | |
Foldable1 ((,) c) Source # | |
Defined in Relude.Extra.Foldable1 | |
(Foldable1 f, Foldable1 g) => Foldable1 (Product f g) Source # | |
Defined in Relude.Extra.Foldable1 | |
(Foldable1 f, Foldable1 g) => Foldable1 (Sum f g) Source # | |
(Foldable1 f, Foldable1 g) => Foldable1 (Compose f g) Source # | |
Defined in Relude.Extra.Foldable1 |