Maintainer | bastiaan.heeren@ou.nl |
---|---|
Stability | provisional |
Portability | portable (depends on ghc) |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
A type class with an implementation for expressing choice and left-biased choice.
- class Choice f where
- data Menu a
- eqMenuBy :: (a -> a -> Bool) -> Menu a -> Menu a -> Bool
- elems :: Menu a -> [a]
- bests :: Menu a -> [a]
- bestsOrdered :: (a -> a -> Ordering) -> Menu a -> [a]
- isEmpty :: Menu a -> Bool
- getByIndex :: Int -> Menu a -> Maybe a
- onMenu :: Choice f => (a -> f b) -> Menu a -> f b
- cut :: Choice f => Menu a -> f a
- cutOn :: Choice f => (a -> Bool) -> Menu a -> f a
- mapWithIndex :: Choice f => (Int -> a -> f b) -> Menu a -> f b
Choice type class
Nothing to choose from.
One element.
(<|>) :: f a -> f a -> f a infixr 3 Source
Normal (unbiased) choice.
(>|>) :: f a -> f a -> f a infixr 3 Source
Left-preference.
(|>) :: f a -> f a -> f a infixr 3 Source
Left-biased choice.
One element from a list (unbiased).
One of the alternatives in a list (unbiased).
Menu data type
eqMenuBy :: (a -> a -> Bool) -> Menu a -> Menu a -> Bool Source
Equality with a comparison function for the elements
Queries
bestsOrdered :: (a -> a -> Ordering) -> Menu a -> [a] Source
Returns only the best elements that are in the menu, with a given ordering.
getByIndex :: Int -> Menu a -> Maybe a Source
Get an element from the menu by its index.
Generalized functions
onMenu :: Choice f => (a -> f b) -> Menu a -> f b Source
Generalized monadic bind, with the arguments flipped.
mapWithIndex :: Choice f => (Int -> a -> f b) -> Menu a -> f b Source
Maps a function over a menu that also takes the index of an element.