Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Pythia.Utils
Contents
Description
This module provides common utilities.
Since: 0.1
Synopsis
- foldAlt :: (Foldable t, Alternative f) => (a -> f b) -> t a -> f b
- foldMap1 :: (Foldable f, Semigroup s) => (a -> s) -> a -> f a -> s
- mAlt :: Alternative f => Maybe (f a) -> f a
- takeLine :: (Ord e, Stream s, Token s ~ Char) => Parsec e s (Tokens s)
- takeLineLabel :: (Ord e, Stream s, Token s ~ Char) => Maybe String -> Parsec e s (Tokens s)
- takeLine_ :: (Ord e, Stream s, Token s ~ Char) => Parsec e s ()
- exeSupported :: MonadPathReader m => OsPath -> m Bool
- headMaybe :: [a] -> Maybe a
- eitherToBool :: Either a b -> Bool
Folding
foldAlt :: (Foldable t, Alternative f) => (a -> f b) -> t a -> f b Source #
Similar to foldMap
but for Alternative
.
Examples
>>>
foldAlt (\c -> if even c then Just c else Nothing) [1,2,3,4]
Just 2
>>>
foldAlt (\c -> if even c then Just c else Nothing) [1,3]
Nothing
Since: 0.1
mAlt :: Alternative f => Maybe (f a) -> f a Source #
Convenience function for mapping a Maybe
to its underlying
Alternative
.
Examples
>>>
mAlt @[] Nothing
[]
>>>
mAlt @[] (Just [1,2,3])
[1,2,3]
Since: 0.1
Parsing
takeLine :: (Ord e, Stream s, Token s ~ Char) => Parsec e s (Tokens s) Source #
takeLineLabel
with no label.
Examples
>>>
parseTest @Void takeLine "some text 123 \n"
"some text 123 "
>>>
parseTest @Void takeLine "some text 123"
1:14: | 1 | some text 123 | ^ unexpected end of input expecting end of line
Since: 0.1
takeLineLabel :: (Ord e, Stream s, Token s ~ Char) => Maybe String -> Parsec e s (Tokens s) Source #
Variant of takeLine
taking in a label.
Examples
>>>
parseTest @Void (takeLineLabel (Just "a label")) "some text 123"
1:14: | 1 | some text 123 | ^ unexpected end of input expecting a label or end of line
Since: 0.1
takeLine_ :: (Ord e, Stream s, Token s ~ Char) => Parsec e s () Source #
Takes everything up to the first new line, returns unit.
Examples
>>>
parseTest @Void takeLine_ "some text 123\n"
()
Since: 0.1
exeSupported :: MonadPathReader m => OsPath -> m Bool Source #
Determines if the executable represented by the string parameter is supported on this system.
Since: 0.1