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

PortabilityHaskell98
Stabilityexperimental
Maintainerwren@community.haskell.org
Safe HaskellSafe-Inferred

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 bSource

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] -> aSource

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] -> aSource

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] -> aSource

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.