Copyright | (c) Justin Le 2018 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Common functions for solutions
Synopsis
- module AOC.Util
- iterateMaybe :: (a -> Maybe a) -> a -> [a]
- loopMaybe :: (a -> Maybe a) -> a -> a
- (!!!) :: [a] -> Int -> a
- dup :: a -> (a, a)
- scanlT :: Traversable t => (b -> a -> b) -> b -> t a -> t b
- scanrT :: Traversable t => (a -> b -> b) -> b -> t a -> t b
- firstRepeated :: Ord a => [a] -> Maybe a
- freqs :: (Foldable f, Ord a) => f a -> Map a Int
- perturbations :: (a -> [a]) -> [a] -> [[a]]
- clearOut :: (Char -> Bool) -> String -> String
- maximumVal :: Ord b => Map a b -> Maybe (a, b)
- maximumValBy :: (b -> b -> Ordering) -> Map a b -> Maybe (a, b)
- minimumVal :: Ord b => Map a b -> Maybe (a, b)
- minimumValBy :: (b -> b -> Ordering) -> Map a b -> Maybe (a, b)
- maximumValNE :: Ord b => NEMap a b -> (a, b)
- maximumValByNE :: (b -> b -> Ordering) -> NEMap a b -> (a, b)
- minimumValNE :: Ord b => NEMap a b -> (a, b)
- minimumValByNE :: (b -> b -> Ordering) -> NEMap a b -> (a, b)
- deleteFinite :: KnownNat n => Finite (n + 1) -> Finite (n + 1) -> Maybe (Finite n)
- foldMapPar :: Monoid b => (a -> b) -> [a] -> b
- foldMapPar1 :: Semigroup b => (a -> b) -> NonEmpty a -> b
- meanVar :: Fractional a => Fold a (a, a)
- eitherItem :: Lens' (Either a a) a
- getDown :: Down a -> a
- type Point = V2 Int
- cardinalNeighbs :: Point -> [Point]
- fullNeighbs :: Point -> [Point]
- mannDist :: (Foldable f, Num a, Num (f a)) => f a -> f a -> a
- memoPoint :: Memo Point
- boundingBox :: (Foldable1 f, Applicative g, Ord a) => f (g a) -> V2 (g a)
- boundingBox' :: Foldable f => f Point -> Maybe (V2 Point)
- parseAsciiMap :: (Char -> Maybe a) -> String -> Map Point a
- asciiGrid :: IndexedFold Point String Char
- newtype ScanPoint = SP {}
- displayAsciiMap :: Char -> Map Point Char -> String
Documentation
module AOC.Util
iterateMaybe :: (a -> Maybe a) -> a -> [a] Source #
Iterate until a Nothing
is produced
loopMaybe :: (a -> Maybe a) -> a -> a Source #
Apply function until Nothing
is produced, and return last produced
value.
scanlT :: Traversable t => (b -> a -> b) -> b -> t a -> t b Source #
scanl
generalized to all Traversable
.
scanrT :: Traversable t => (a -> b -> b) -> b -> t a -> t b Source #
scanr
generalized to all Traversable
.
firstRepeated :: Ord a => [a] -> Maybe a Source #
Lazily find the first repeated item.
perturbations :: (a -> [a]) -> [a] -> [[a]] Source #
Collect all possible single-item perturbations from a given perturbing function.
perturbations (\i -> [i - 1, i + 1]) [0,10,100]
[ [-1,10,100]
, [ 1,10,100] , [ 0, 9,100] , [ 0,11,100] , [ 0,10, 99] , [ 0,10,101] ]
clearOut :: (Char -> Bool) -> String -> String Source #
Clear out characters not matching a predicate
maximumVal :: Ord b => Map a b -> Maybe (a, b) Source #
Get the key-value pair corresponding to the maximum value in the map
maximumValBy :: (b -> b -> Ordering) -> Map a b -> Maybe (a, b) Source #
Get the key-value pair corresponding to the maximum value in the map, with a custom comparing function.
'maximumVal' == 'maximumValBy' 'compare'
minimumVal :: Ord b => Map a b -> Maybe (a, b) Source #
Get the key-value pair corresponding to the minimum value in the map
minimumValBy :: (b -> b -> Ordering) -> Map a b -> Maybe (a, b) Source #
Get the key-value pair corresponding to the minimum value in the map, with a custom comparing function.
'minimumVal' == 'minimumValBy' 'compare'
maximumValNE :: Ord b => NEMap a b -> (a, b) Source #
Version of maximumVal
for nonempty maps.
maximumValByNE :: (b -> b -> Ordering) -> NEMap a b -> (a, b) Source #
Version of maximumValBy
for nonempty maps.
minimumValNE :: Ord b => NEMap a b -> (a, b) Source #
Version of minimumVal
for nonempty maps.
minimumValByNE :: (b -> b -> Ordering) -> NEMap a b -> (a, b) Source #
Version of minimumValBy
for nonempty maps.
deleteFinite :: KnownNat n => Finite (n + 1) -> Finite (n + 1) -> Maybe (Finite n) Source #
Delete a potential value from a Finite
.
foldMapPar :: Monoid b => (a -> b) -> [a] -> b Source #
foldMap
, but in parallel.
eitherItem :: Lens' (Either a a) a Source #
2D Maps
cardinalNeighbs :: Point -> [Point] Source #
fullNeighbs :: Point -> [Point] Source #
boundingBox :: (Foldable1 f, Applicative g, Ord a) => f (g a) -> V2 (g a) Source #
Find the minimum and maximum x and y from a collection of points.
Returns
.V2
(V2 xMin yMin) (V2 xMax yMax)
boundingBox' :: Foldable f => f Point -> Maybe (V2 Point) Source #
A version of boundingBox
that works for normal possibly-empty lists.