| License | BSD3 |
|---|---|
| Maintainer | tbidne@gmail.com |
| Safe Haskell | None |
| Language | Haskell2010 |
Common.Utils
Description
Exports utility functions
Synopsis
- diffTime :: TimeSpec -> TimeSpec -> RNonNegative Int
- divWithRem :: Integral a => RNonNegative a -> RPositive a -> (a, a)
- eitherCompose :: (a -> Either b c) -> (c -> Either d e) -> a -> Either () e
- eitherComposeMay :: (a -> Either b c) -> (c -> Either d e) -> a -> Maybe e
- eitherJoin :: Either a (Either b c) -> Either () c
- eitherToMaybe :: Either a b -> Maybe b
- formatSeconds :: RNonNegative Int -> Text
- matchAndStrip :: Eq a => [a] -> [a] -> Maybe [a]
- monoBimap :: Bifunctor f => (a -> b) -> f a a -> f b b
- showToText :: Show a => a -> Text
- startsWith :: Eq a => [a] -> [a] -> Maybe [a]
Documentation
diffTime :: TimeSpec -> TimeSpec -> RNonNegative Int Source #
For given \(x, y\), returns the absolute difference \(|x - y|\).
divWithRem :: Integral a => RNonNegative a -> RPositive a -> (a, a) Source #
For \(n \ge 0, d > 0\), returns non-negative \((e, r)\) such that
\[ \begin{align} de + r = n \\ r < n \\ \end{align} \]
eitherCompose :: (a -> Either b c) -> (c -> Either d e) -> a -> Either () e Source #
Composes Either functions.
eitherComposeMay :: (a -> Either b c) -> (c -> Either d e) -> a -> Maybe e Source #
Composition of eitherToMaybe to eitherCompose.
eitherJoin :: Either a (Either b c) -> Either () c Source #
Joins a composed Either in the natural way.
formatSeconds :: RNonNegative Int -> Text Source #
For \(n \ge 0\) seconds, returns a Text description of the minutes
and seconds.
matchAndStrip :: Eq a => [a] -> [a] -> Maybe [a] Source #
monoBimap :: Bifunctor f => (a -> b) -> f a a -> f b b Source #
Convenience function for mapping the same function over a monomorphic bifunctor.
startsWith :: Eq a => [a] -> [a] -> Maybe [a] Source #
Determines if the second parameter is a prefix of the first, returns the rest if so. That is,
\[ \newcommand\doubleplus{+\kern-1.3ex+\kern0.8ex} \mathrm{startsWith}(xs, ys) = \begin{cases} \mathrm{Just\,} zs, &xs = ys \doubleplus zs \\ \mathrm{Nothing}, &\mathrm{otherwise} \end{cases} \]
Can be called infix, e.g.
"hello world" `startsWith` "hello" -->Just" world"