list-extras-0.4.1.4: Common not-so-common functions for lists

CopyrightCopyright (c) 2007--2015 wren gayle romano
LicenseBSD3
Maintainerwren@community.haskell.org
Stabilityexperimental
PortabilityHaskell98
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.List.Extras.Argmax

Contents

Description

This module provides variants of the maximum and minimum functions which return the elements for which some function is maximized or minimized.

Synopsis

Utility functions

catchNull :: ([a] -> b) -> [a] -> Maybe b Source

Apply a list function safely, i.e. when the list is non-empty. All other functions will throw errors on empty lists, so use this to make your own safe variations.

Generic versions

argmaxBy :: (b -> b -> Ordering) -> (a -> b) -> [a] -> a Source

Return an element of the list which maximizes the function according to a user-defined ordering.

argmaxesBy :: (b -> b -> Ordering) -> (a -> b) -> [a] -> [a] Source

Return all elements of the list which maximize the function according to a user-defined ordering.

argmaxWithMaxBy :: (b -> b -> Ordering) -> (a -> b) -> [a] -> (a, b) Source

Return an element of the list which maximizes the function according to a user-defined ordering, and return the value of the function at that element as well.

argmaxesWithMaxBy :: (b -> b -> Ordering) -> (a -> b) -> [a] -> ([a], b) Source

Return all elements of the list which maximize the function according to a user-defined ordering, and return the value of the function at those elements as well.

Maximum variations

argmax :: Ord b => (a -> b) -> [a] -> a Source

Return an element of the list which maximizes the function.

argmaxes :: Ord b => (a -> b) -> [a] -> [a] Source

Return all elements of the list which maximize the function.

argmaxWithMax :: Ord b => (a -> b) -> [a] -> (a, b) Source

Return an element of the list which maximizes the function, and return the value of the function at that element as well.

argmaxesWithMax :: Ord b => (a -> b) -> [a] -> ([a], b) Source

Return all elements of the list which maximize the function, and return the value of the function at those elements as well.

Minimum variations

argmin :: Ord b => (a -> b) -> [a] -> a Source

Return an element of the list which minimizes the function.

argmins :: Ord b => (a -> b) -> [a] -> [a] Source

Return all elements of the list which minimize the function.

argminWithMin :: Ord b => (a -> b) -> [a] -> (a, b) Source

Return an element of the list which minimizes the function, and return the value of the function at that element as well.

argminsWithMin :: Ord b => (a -> b) -> [a] -> ([a], b) Source

Return all elements of the list which minimize the function, and return the value of the function at those elements as well.