code-conjure-0.5.6: synthesize Haskell functions out of partial definitions
Copyright(c) 2021 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Conjure.Utils

Description

An internal module of Conjure. This exports List, Maybe, Function and a few other simple utitilites.

Synopsis

Documentation

module Data.List

module Data.Maybe

module Data.Tuple

count :: (a -> Bool) -> [a] -> Int Source #

Counts the number of occurrences on a list.

nubOn :: Eq b => (a -> b) -> [a] -> [a] Source #

Nubs using a given field.

nubSort :: Ord a => [a] -> [a] Source #

Equivalent to nub . sort but running in O(n log n).

mzip :: Monoid a => [a] -> [a] -> [a] Source #

Zips Monoid values leaving trailing values.

> mzip ["ab","cd"] ["ef"]
["abef","cd"]

groupOn :: Eq b => (a -> b) -> [a] -> [[a]] Source #

Group values using a given field selector.

idIO :: (a -> IO ()) -> a -> a Source #

WARNING: uses unsafePerformIO and should only be used for debugging!

> idIO print 10
10
10

mapHead :: (a -> a) -> [a] -> [a] Source #

Applies a function to the head of a list.

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

Return sets of values based on the list.

The values in the list must me unique.

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

Like head but allows providing a default value.

allEqual :: Eq a => [a] -> Bool Source #

Checks if all elements of a list are equal.

Exceptionally this function returns false for an empty or unit list.

choices :: [a] -> [(a, [a])] Source #

Lists choices of values.

choicesThat :: (a -> [a] -> Bool) -> [a] -> [(a, [a])] Source #

Lists choices of values that follow a property.

foldr0 :: (a -> a -> a) -> a -> [a] -> a Source #

A variation of foldr that only uses "zero" when the list is empty

indent :: String -> String Source #

Indents a block of text by 4 spaces

indentBy :: Int -> String -> String Source #

Indents a block of text with the provided amount of spaces

classify :: Eq a => [a] -> [[a]] #

Classify values using their Eq instance.

> classify [1,2,3,1,2,1]
[[1,1,1],[2,2],[3]]

(cf. classifyBy, classifyOn)

classifyBy :: (a -> a -> Bool) -> [a] -> [[a]] #

Classify values by a given comparison function.

> classifyBy (\(x,_) (y,_) -> x == y) [(1,1),(1,2),(2,1),(2,2)]
[[(1,1),(1,2)],[(2,1),(2,2)]]

(cf. classify, classifyOn)

classifyOn :: Eq b => (a -> b) -> [a] -> [[a]] #

Classify values based on the result of a given function.

> classifyOn head ["sheep", "chip", "ship", "cheap"]
[["sheep","ship"],["chip","cheap"]]
> classifyOn odd [1,2,3,4,5,6]
[[1,3,5],[2,4,6]]

(cf. classify, classifyBy)