hunt-searchengine-0.3.0.1: A search and indexing engine.

Safe HaskellNone
LanguageHaskell98

Hunt.Utility

Contents

Description

General utitlity functions.

Synopsis

Function Composition

(.::) :: (c -> d) -> (a -> b -> c) -> a -> b -> d Source

The boob operator.

(.:::) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e Source

The Total Recall operator.

Safe / Total Functions

head' :: [a] -> Maybe a Source

Safe head.

Strict Functions

foldM' :: Monad m => (a -> b -> m a) -> a -> [b] -> m a Source

Strict version of foldM.

Monadic Functions

foldlWithKeyM :: Monad m => (b -> k -> a -> m b) -> b -> Map k a -> m b Source

foldlM for Map with key.

foldrWithKeyM :: Monad m => (k -> a -> b -> m b) -> b -> Map k a -> m b Source

foldrM for Map with key.

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

Monadic when.

Maybe Helper

catMaybesSet :: Ord a => Set (Maybe a) -> [a] Source

catMaybes on a Set instead of a List.

Either Helper

isLeft :: Either a b -> Bool Source

Test if Either is a Left value.

isRight :: Either a b -> Bool Source

Test if Either is a Right value.

fromLeft :: Either a b -> a Source

Unwraps a Left value - fails on Right.

fromRight :: Either a b -> b Source

Unwraps a Right value - fails on Left.

List Helper

unbox :: [a] -> a Source

Unbox a singleton.

Note: This fails if the list is not a singleton.

unboxM :: [a] -> Maybe a Source

Unbox a singleton in a safe way with Maybe.

isSingleton :: [a] -> Bool Source

Test if the list contains a single element.

split :: Eq a => [a] -> [a] -> [[a]] Source

Split a string into seperate strings at a specific character sequence.

partitionListByLength :: Int -> [a] -> [[a]] Source

partition the list of input data into a list of input data lists of approximately the same specified length

partitionListByCount :: Int -> [a] -> [[a]] Source

partition the list of input data into a list of a specified number of input data lists with approximately the same length

descending :: Ord a => a -> a -> Ordering Source

To use with sortBy.

String Helper

strip :: String -> String Source

Removes leading and trailing whitespace from a string.

stripl :: String -> String Source

Removes leading whitespace from a string.

stripr :: String -> String Source

Removes trailing whitespace from a string.

stripWith :: (a -> Bool) -> [a] -> [a] Source

Strip leading and trailing elements matching a predicate.

escape :: String -> String Source

Escapes non-alphanumeric or space characters in a String

Text Helper

showText :: Show a => a -> Text Source

Aeson Helper

object' :: [[Pair]] -> Value Source

Like object to use with .=?, .== and .\.. This allows omitting (default) values in ToJSON instances.

toJSON (Example maybe list float) = object' $
  [ "maybe" .=? maybe .\. isNothing
  , "list"  .=? list  .\. null
  , "float" .=? float .\. (== 1.0)
  ]

(.=?) :: ToJSON a => Text -> (a, a -> Bool) -> [Pair] infixl 8 Source

Like .= but allows omitting of (default) values in ToJSON instances.

See object'.

(.==) :: ToJSON a => Text -> a -> [Pair] Source

(.\.) :: ToJSON a => a -> (a -> Bool) -> (a, a -> Bool) Source

Use with .=? to specify which value to omit.

See object'.

Types

data TypeDummy Source

A dummy type without constructor.