pythia-0.1: A utility program for retrieving system information.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Pythia.Utils

Description

This module provides common utilities.

Since: 0.1

Synopsis

Folding

foldAlt :: (Foldable t, Alternative f) => (a -> f b) -> t a -> f b Source #

Similar to foldMap but for Alternative.

Examples

Expand
>>> 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

foldMap1 :: (Foldable f, Semigroup s) => (a -> s) -> a -> f a -> s Source #

Relaxes foldMap's Monoid constraint to Semigroup. Requires a starting value. This will have to do until semigroupoids' Foldable1 is in base.

Since: 0.1

mAlt :: Alternative f => Maybe (f a) -> f a Source #

Convenience function for mapping a Maybe to its underlying Alternative.

Examples

Expand
>>> 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

Expand
>>> 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

Expand
>>> 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

Expand
>>> 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

Miscellaneous

headMaybe :: [a] -> Maybe a Source #

Total version of head.

Examples

Expand
>>> headMaybe []
Nothing
>>> headMaybe [3, 4]
Just 3

Since: 0.1

eitherToBool :: Either a b -> Bool Source #

Maps Left to False, Right to True.

Examples

Expand
>>> eitherToBool (Left ())
False
>>> eitherToBool (Right ())
True

Since: 0.1