:: [Bool] -> Bool -package:ghc

and returns the conjunction of a Boolean list. For the result to be True, the list must be finite; False, however, results from a False value at a finite index of a finite or infinite list.

Examples

>>> and []
True
>>> and [True]
True
>>> and [False]
False
>>> and [True, True, False]
False
>>> and (False : repeat True) -- Infinite list [False,True,True,True,True,True,True...
False
>>> and (repeat True)
* Hangs forever *
or returns the disjunction of a Boolean list. For the result to be False, the list must be finite; True, however, results from a True value at a finite index of a finite or infinite list.

Examples

>>> or []
False
>>> or [True]
True
>>> or [False]
False
>>> or [True, True, False]
True
>>> or (True : repeat False) -- Infinite list [True,False,False,False,False,False,False...
True
>>> or (repeat False)
* Hangs forever *
Test whether a list is empty.
>>> null []
True

>>> null [1]
False

>>> null [1..]
False
A composition of not and null.
notNull []  == False
notNull [1] == True
\xs -> notNull xs == not (null xs)
A version specialized to lists to avoid errors such as taking null of Maybe [a] instead of [a]. Such errors are hard to detect, because the type of elements of the list is not constrained.
Is the given list not null? Equivalent to not . null
Are all elements the same.
allSame [1,1,2] == False
allSame [1,1,1] == True
allSame [1]     == True
allSame []      == True
allSame (1:1:2:undefined) == False
\xs -> allSame xs == (length (nub xs) <= 1)
Is there any element which occurs more than once.
anySame [1,1,2] == True
anySame [1,2,3] == False
anySame (1:2:1:undefined) == True
anySame [] == False
\xs -> anySame xs == (length (nub xs) < length xs)
>>> allEqual "aab"
False

>>> allEqual "aaa"
True

>>> allEqual "aa"
True

>>> allEqual "a"
True

>>> allEqual ""
True
Check whether all elements in a list are distinct from each other. Assumes that the Eq instance stands for an equivalence relation. O(n²) in the worst case distinct xs == True.
Checks if all the elements in the list are equal. Assumes that the Eq instance stands for an equivalence relation. O(n).
Test if all elements of a list are equal; returns True for empty list.
Test whether an index is a diagonal one.
>>> isDiag [2,2,2]
True

>>> isDiag [1,2]
False
Check if all elements in a list are distinct. Note that empty or singleton lists are always distinct.
>>> distinct []
True

>>> distinct [1]
True

>>> distinct [1, 2, 3]
True

>>> distinct [1, 2, 2]
False
Checks if all elements of a list are equal.
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.
O(n). Whether the elements are all equal.
>>> allEqual [1..]
False

>>> allEqual [3, 3, 3, 3]
True

>>> allEqual []
True

>>> allEqual [1]
True
O(n). Whether all adjacent pairs of elements are different. Useful for determining whether a sorted list is all unique.
>>> allAdjUnique [1, 2, 3, 2]
True

>>> allAdjUnique [1, 2, 2, 3]
False

>>> allAdjUnique []
True

>>> allAdjUnique [1]
True
O(n). Whether the input is a palindrome, i.e., the same forwards and backwards.
>>> palindrome "rotor"
True

>>> palindrome "rover"
False

>>> palindrome ""
True

>>> palindrome "a"
True