relude-0.4.0: Custom prelude from Kowainik

Copyright(c) 2011-2015 Edward Kmett
(c) 2018 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellSafe
LanguageHaskell2010

Relude.Extra.Foldable1

Description

 
Synopsis

Documentation

class Foldable f => Foldable1 f where Source #

The class of foldable data structures that cannot be empty.

Minimal complete definition

foldMap1

Methods

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 :| []

head1 :: f a -> a Source #

The first element of a non-empty data structure.

>>> head1 (1 :| [2, 3, 4])
1

last1 :: f a -> a Source #

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 # 
Instance details

Defined in Relude.Extra.Foldable1

Methods

foldMap1 :: Semigroup m => (a -> m) -> Identity a -> m Source #

fold1 :: Semigroup m => Identity m -> m Source #

toNonEmpty :: Identity a -> NonEmpty a Source #

head1 :: Identity a -> a Source #

last1 :: Identity a -> a Source #

maximum1 :: Ord a => Identity a -> a Source #

minimum1 :: Ord a => Identity a -> a Source #

Foldable1 NonEmpty Source # 
Instance details

Defined in Relude.Extra.Foldable1

Methods

foldMap1 :: Semigroup m => (a -> m) -> NonEmpty a -> m Source #

fold1 :: Semigroup m => NonEmpty m -> m Source #

toNonEmpty :: NonEmpty a -> NonEmpty a Source #

head1 :: NonEmpty a -> a Source #

last1 :: NonEmpty a -> a Source #

maximum1 :: Ord a => NonEmpty a -> a Source #

minimum1 :: Ord a => NonEmpty a -> a Source #

Foldable1 ((,) c) Source # 
Instance details

Defined in Relude.Extra.Foldable1

Methods

foldMap1 :: Semigroup m => (a -> m) -> (c, a) -> m Source #

fold1 :: Semigroup m => (c, m) -> m Source #

toNonEmpty :: (c, a) -> NonEmpty a Source #

head1 :: (c, a) -> a Source #

last1 :: (c, a) -> a Source #

maximum1 :: Ord a => (c, a) -> a Source #

minimum1 :: Ord a => (c, a) -> a Source #

(Foldable1 f, Foldable1 g) => Foldable1 (Product f g) Source # 
Instance details

Defined in Relude.Extra.Foldable1

Methods

foldMap1 :: Semigroup m => (a -> m) -> Product f g a -> m Source #

fold1 :: Semigroup m => Product f g m -> m Source #

toNonEmpty :: Product f g a -> NonEmpty a Source #

head1 :: Product f g a -> a Source #

last1 :: Product f g a -> a Source #

maximum1 :: Ord a => Product f g a -> a Source #

minimum1 :: Ord a => Product f g a -> a Source #

(Foldable1 f, Foldable1 g) => Foldable1 (Sum f g) Source # 
Instance details

Defined in Relude.Extra.Foldable1

Methods

foldMap1 :: Semigroup m => (a -> m) -> Sum f g a -> m Source #

fold1 :: Semigroup m => Sum f g m -> m Source #

toNonEmpty :: Sum f g a -> NonEmpty a Source #

head1 :: Sum f g a -> a Source #

last1 :: Sum f g a -> a Source #

maximum1 :: Ord a => Sum f g a -> a Source #

minimum1 :: Ord a => Sum f g a -> a Source #

(Foldable1 f, Foldable1 g) => Foldable1 (Compose f g) Source # 
Instance details

Defined in Relude.Extra.Foldable1

Methods

foldMap1 :: Semigroup m => (a -> m) -> Compose f g a -> m Source #

fold1 :: Semigroup m => Compose f g m -> m Source #

toNonEmpty :: Compose f g a -> NonEmpty a Source #

head1 :: Compose f g a -> a Source #

last1 :: Compose f g a -> a Source #

maximum1 :: Ord a => Compose f g a -> a Source #

minimum1 :: Ord a => Compose f g a -> a Source #

foldl1' :: (a -> a -> a) -> NonEmpty a -> a Source #

Strictly folds non-empty structure with given function f:

foldl1' f [x0, x1, x2 ...] = f (f x0 x1) x2 ...
>>> foldl1' (++) ([1,2] :| [[3,4], [5,6]])
[1,2,3,4,5,6]