iota-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

My.Prelude

Synopsis

Stream utils

rep :: Monad m => Int -> (Int -> m ()) -> m () Source #

rep1 :: Monad m => Int -> (Int -> m ()) -> m () Source #

rev :: Monad m => Int -> (Int -> m ()) -> m () Source #

rev1 :: Monad m => Int -> (Int -> m ()) -> m () Source #

(..<) :: Monad m => Int -> Int -> Stream m Int infix 4 Source #

>>> runIdentity $ MS.toList (0..<5)
[0,1,2,3,4]

(>..) :: Monad m => Int -> Int -> Stream m Int infix 4 Source #

>>> runIdentity $ MS.toList (5>..0)
[4,3,2,1,0]

stride :: Monad m => Int -> Int -> Int -> Stream m Int Source #

>>> runIdentity $ MS.toList (stride 0 10 3)
[0,3,6,9]

liftMS :: Monad m => Stream Id a -> Stream m a Source #

Vector utils

asUVector :: Vector a -> Vector a Source #

asBVector :: Vector a -> Vector a Source #

lowerBound :: (Ord a, Vector v a) => v a -> a -> Int Source #

>>> lowerBound (U.fromList "122333") '2'
1
>>> lowerBound (U.fromList "122333") '0'
0
>>> lowerBound (U.fromList "122333") '9'
6

upperBound :: (Ord a, Vector v a) => v a -> a -> Int Source #

>>> upperBound (U.fromList "122333") '2'
3
>>> upperBound (U.fromList "122333") '0'
0
>>> upperBound (U.fromList "122333") '9'
6

radixSort :: Vector Int -> Vector Int Source #

>>> radixSort $ U.fromList [3,1,4,1,5,9]
[1,1,3,4,5,9]
>>> radixSort $ U.fromList [-3,-1,-4,1,5,9]
[1,5,9,-4,-3,-1]

runLengthEncode :: (Eq a, Vector v a, Vector v (a, Int)) => v a -> v (a, Int) Source #

>>> runLengthEncode $ U.fromList "abbccc"
[('a',1),('b',2),('c',3)]
>>> runLengthEncode $ U.fromList ""
[]

streamRLE :: (Eq a, Monad m) => Stream m a -> Stream m (a, Int) Source #

forAccum :: (Vector v a, Vector v b) => s -> v a -> (s -> a -> (s, b)) -> v b Source #

>>> forAccum (0 :: Int) (U.fromList "abc") $ \acc c -> (acc + 1, (acc, c))
[(0,'a'),(1,'b'),(2,'c')]

mapAccum :: (Vector v a, Vector v b) => (s -> a -> (s, b)) -> s -> v a -> v b Source #

forAccumM :: (PrimMonad m, Vector v a, Vector v b) => s -> v a -> (s -> a -> m (s, b)) -> m (v b) Source #

forAccumM_ :: (Monad m, Vector v b) => a -> v b -> (a -> b -> m a) -> m () Source #

mapAccumM :: (PrimMonad m, Vector v a, Vector v b) => (s -> a -> m (s, b)) -> s -> v a -> m (v b) Source #

forAccumMaybe :: (Vector v a, Vector v b) => s -> v a -> (s -> a -> (s, Maybe b)) -> v b Source #

mapAccumMaybe :: (Vector v a, Vector v b) => (s -> a -> (s, Maybe b)) -> s -> v a -> v b Source #

forAccumMaybeM :: (PrimMonad m, Vector v a, Vector v b) => s -> v a -> (s -> a -> m (s, Maybe b)) -> m (v b) Source #

mapAccumMaybeM :: (PrimMonad m, Vector v a, Vector v b) => (s -> a -> m (s, Maybe b)) -> s -> v a -> m (v b) Source #

bundleAccumM :: Monad m => (s -> a -> m (s, b)) -> s -> Bundle m v a -> Bundle m v b Source #

bundleAccumMaybeM :: Monad m => (s -> a -> m (s, Maybe b)) -> s -> Bundle m v a -> Bundle m v b Source #

streamAccumM :: Monad m => (s -> a -> m (s, b)) -> s -> Stream m a -> Stream m b Source #

streamAccumMaybeM :: Monad m => (s -> a -> m (s, Maybe b)) -> s -> Stream m a -> Stream m b Source #

stream :: Vector v a => v a -> Stream Id a Source #

streamM :: (Vector v a, Monad m) => v a -> Stream m a Source #

unstream :: Vector v a => Int -> Stream Id a -> v a Source #

>>> asUVector . unstream 10 . stream $ U.fromList "abc"
"abc"

unstreamM :: (PrimMonad m, Vector v a) => Int -> Stream m a -> m (v a) Source #

Bits utils

shiftRL :: Int -> Int -> Int infixl 8 Source #

unsafeShiftRL :: Int -> Int -> Int infixl 8 Source #

>>> unsafeShiftR (-1) 1
-1
>>> unsafeShiftRL (-1) 1
9223372036854775807

(!>>>.) :: Int -> Int -> Int infixl 8 Source #

Parser utils

uvectorN :: Unbox a => Int -> PrimParser a -> PrimParser (Vector a) Source #

bvectorN :: Int -> PrimParser a -> PrimParser (Vector a) Source #

gvectorN :: Vector v a => Int -> PrimParser a -> PrimParser (v a) Source #

streamN :: Int -> PrimParser a -> PrimParser (Stream Id a) Source #

uvector :: Unbox a => PrimParser a -> PrimParser (Vector a) Source #

gvector :: Vector v a => PrimParser a -> PrimParser (v a) Source #

Builder utils

unlinesB :: Vector v a => (a -> Builder) -> v a -> Builder Source #

unwordsB :: Vector v a => (a -> Builder) -> v a -> Builder Source #

concatB :: Vector v a => (a -> Builder) -> v a -> Builder Source #

matrixB :: Vector v a => Int -> Int -> (a -> Builder) -> v a -> Builder Source #

>>> matrixB 2 3 B.intDec $ U.fromListN 6 [1, 2, 3, 4, 5, 6]
"1 2 3\n4 5 6\n"

gridB :: Vector v a => Int -> Int -> (a -> Builder) -> v a -> Builder Source #

>>> gridB 2 3 B.char7 $ U.fromListN 6 ".#.#.#"
".#.\n#.#\n"
>>> gridB 2 3 B.intDec $ U.fromListN 6 [1, 2, 3, 4, 5, 6]
"123\n456\n"

sizedB :: Vector v a => (v a -> Builder) -> v a -> Builder Source #

yesnoB :: Bool -> Builder Source #

>>> yesnoB True
"Yes"
>>> yesnoB False
"No"

pairB :: (a -> Builder) -> (b -> Builder) -> (a, b) -> Builder Source #

>>> pairB B.intDec B.intDec $ (0, 1)
"0 1"
>>> pairB B.intDec (pairB B.intDec B.intDec) $ (0, (1, 2))
"0 1 2"

showB :: Show a => a -> Builder Source #

showLnB :: Show a => a -> Builder Source #

lfB :: Builder Source #

>>> lfB
"\n"

spB :: Builder Source #

>>> spB
" "

Misc

neighbor4 :: Applicative f => Int -> Int -> Int -> (Int -> f ()) -> f () Source #

binarySearchM :: Monad m => Int -> Int -> (Int -> m Bool) -> m Int Source #

binarySearch :: Int -> Int -> (Int -> Bool) -> Int Source #

runSolver :: (a -> IO ()) -> PrimParser a -> IO () Source #