spiros-0.4.0: Spiros Boosalis's Custom Prelude

Safe HaskellNone
LanguageHaskell2010

Prelude.Spiros.Utilities

Description

These identifiers are "soft" overrides, they generalize the signatures of their Prelude namesakes:

These symbols are "hard" overrides, they are completely different from Prelude:

  • >: forward-composition
  • <: backward-composition (i.e. '(.)')
Synopsis

Documentation

map :: Functor f => (a -> b) -> f a -> f b Source #

(generalization) = fmap

sequence :: (Traversable t, Applicative f) => t (f a) -> f (t a) Source #

(generalization) = sequenceA

sequence_ :: (Foldable t, Applicative f) => t (f a) -> f () Source #

(generalization) = sequenceA_

(>) :: (a -> b) -> (b -> c) -> a -> c infixr 9 Source #

forwards composition

e.g. "f, then g, then h"

forwards x
 = x
 & f
 > g
 > h

same precedence/associativity as .

(<) :: (b -> c) -> (a -> b) -> a -> c infixr 9 Source #

backwards composition

e.g. "h, after g, after f"

backwards x
 = h
 < g
 < f
 $ x

same precedence/associativity as .

lessThan :: Ord a => a -> a -> Bool infix 4 Source #

same precedence/associativity as "Prelude.<"

greaterThan :: Ord a => a -> a -> Bool infix 4 Source #

same precedence/associativity as "Prelude.>"

(-:) :: a -> b -> (a, b) infix 1 Source #

(-:) = (,)

fake dictionary literal syntax:

 [ "a"-: 1
 , "b"-: 2
 , "c"-: 1+2
 ] :: [(String,Integer)]

todo :: a Source #

Deprecated: use { ERROR TODO }

nothing :: Applicative m => m () Source #

= pure ()

returning :: Applicative m => (a -> b) -> a -> m b Source #

Raise a Function Arrow into a Kleisli Arrow.

a convenience function for composing pure functions between "kleislis" in monadic sequences.

Definition:

= (pure .)
returning f ≡ f >>> return

returning f ≡ x -> return (f x)

Usage:

readFile "example.txt" >>= returning show >>= forceIO

maybe2either :: e -> Maybe a -> Either e a Source #

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

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

list :: r -> (a -> [a] -> r) -> [a] -> r Source #

unsafeNatural :: Integral i => i -> Natural Source #

unsafeNatural :: Int -> Natural  

ratio :: Integral a => a -> a -> Ratio a infixl 7 Source #

an alias, since (%) is prime symbolic real estate.

($>) :: Functor f => f a -> b -> f b Source #

($>) = flip (<$)

(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 5 Source #

Infix flipped fmap.

(<&>) = flip fmap

NOTE: conflicts with the lens package

nth :: Natural -> [a] -> Maybe a Source #

Safely get the n-th item in the given list.

>>> nth 1 ['a'..'c']
Just 'b'
>>> nth 1 []
Nothing

snoc :: [a] -> a -> [a] Source #

reverse cons

toInt :: Integral a => a -> Int Source #

(NOTE truncates large integral types).

index :: Integral n => [a] -> n -> Maybe a Source #

safely-partial (!)

shown :: forall a t. (Show a, IsString t) => a -> t Source #

constructors :: BoundedEnum a => proxy a -> [a] Source #

>>> pBool = Proxy :: Proxy Bool
>>> constructors pBool
[False,True]

constructors' :: forall a. BoundedEnum a => [a] Source #

like constructors, but with an implicit type parameter.

>>> constructors' == [False,True]
True
> :set -XTypeApplications
> constructors' @Bool
False,True

identity :: Category cat => a `cat` a Source #

compose :: Category cat => (b `cat` c) -> (a `cat` b) -> a `cat` c Source #

typeName :: forall proxy a t. (Typeable a, IsString t) => proxy a -> t Source #

whenM :: Monad m => m Bool -> m () -> m () Source #

unlessM :: Monad m => m Bool -> m () -> m () Source #

runReaderT' :: r -> ReaderT r m a -> m a Source #

runStateT' :: s -> StateT s m a -> m (a, s) Source #

evalStateT' :: Monad m => s -> StateT s m a -> m a Source #

execStateT' :: Monad m => s -> StateT s m a -> m s Source #

runState' :: s -> State s a -> (a, s) Source #

newtype Time Source #

A number of microseconds (there are one million microseconds per second). An integral number because it's the smallest resolution for most GHC functions. Int because GHC frequently represents integrals as Ints (for efficiency).

Has smart constructors for common time units; in particular, for thread delays, and for human-scale durations.

Which also act as self-documenting (psuedo-keyword-)arguments for threadDelay, via delayFor.

Constructors

Time 

Fields

delayFor :: MonadIO m => Time -> m () Source #

delaySeconds :: MonadIO m => Int -> m () Source #

io :: MonadIO m => IO a -> m a Source #

forkever_ :: IO () -> IO () Source #

forceIO :: NFData a => a -> IO a Source #

forceIO_ :: NFData a => a -> IO () Source #

firstSetEnvironmentVariable :: String -> [String] -> IO String Source #

Return the value of the first environment variable that's been set, or a default value if all are unset.

Examples:

> firstSetEnvironmentVariable "/usr/run" [ "XDG_RUNTIME_HOME", "TMP" ]

Properties:

firstSetEnvironmentVariable x [] ≡ return x

firstNonemptyEnvironmentVariable :: String -> [String] -> IO String Source #

Return the first **nonempty** value among the given environment variables, or a default value if all are either unset or set-to-empty.

Examples:

> firstNonemptyEnvironmentVariable "usrrun" [ XDG_RUNTIME_HOME, TMP ]

Properties:

firstNonemptyEnvironmentVariable x [] ≈ return x

Notes: