code-conjure-0.5.10: synthesize Haskell functions out of partial definitions
Copyright(c) 2021-2024 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.

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

allEqual2 :: 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.

This returns true when all elements are equal and the list has a length greater than or equal to two.

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)

none :: (a -> Bool) -> [a] -> Bool Source #

updateAt :: Int -> (a -> a) -> [a] -> [a] Source #

Updates the value in a list at a given position.

> updateAt 2 (*10) [1,2,3,4]
[1,2,30,4]

first :: (a -> a') -> (a, b) -> (a', b) Source #

Applies a function to the first element of a pair. Often known on the wild as mapFst.

> first (*10) (1,2)
(10,2)

second :: (b -> b') -> (a, b) -> (a, b') Source #

Applies a function to the second element of a pair. Often known on the wild as mapSnd.

> second (*100) (1,2)
(1,200)

both :: (a -> b) -> (a, a) -> (b, b) Source #

(+++) :: Ord a => [a] -> [a] -> [a] infixr 5 Source #

isSubsetOf :: Ord a => [a] -> [a] -> Bool #

O(n log n). Checks that all elements of the first list are elements of the second.