# Int -> [a] -> a +containers

*O(log n)*. replicate n x is a sequence consisting of n copies of x.

*O(min(n,W))*. The expression (findWithDefault def k map) returns the value at key k or returns def when the key is not an element of the map.
> findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
> findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
*O(1)*. A map of one element.
> singleton 1 'a' == fromList [(1, 'a')]
> size (singleton 1 'a') == 1

*O(min(n,W))*. Delete a value in the set. Returns the original set when the value was not present.

*O(min(n,W))*. Add a value to the set. There is no left- or right bias for IntSets.

*O(n)*. Constructs a sequence by repeated application of a function to a seed value.
> iterateN n f x = fromList (Prelude.take n (Prelude.iterate f x))

*O(log(min(i,n-i)))*. Replace the element at the specified position. If the position is out of range, the original sequence is returned.

*O(min(n,W))*. Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value, i.e. insert is equivalent to insertWith const.
> insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')]
> insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')]
> insert 5 'x' empty == singleton 5 'x'
*O(min(n,W))*. Insert with a combining function. insertWith f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f new_value old_value.
> insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")]
> insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
> insertWith (++) 5 "xxx" empty == singleton 5 "xxx"
*Deprecated.* As of version 0.5, replaced by insertWith.
*O(log n)*. Same as insertWith, but the result of the combining function is evaluated to WHNF before inserted to the map.
*O(min(n,W))*. Insert with a combining function. insertWithKey f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f key new_value old_value.
> let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
> insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")]
> insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
> insertWithKey f 5 "xxx" empty == singleton 5 "xxx"
*O(min(n,W))*. Insert with a combining function. insertWithKey f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f key new_value old_value.
> let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
> insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")]
> insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
> insertWithKey f 5 "xxx" empty == singleton 5 "xxx"
If the key exists in the map, this function is lazy in x but strict in the result of f.
*Deprecated.* As of version 0.5, replaced by insertWithKey.
*O(log n)*. Same as insertWithKey, but the result of the combining function is evaluated to WHNF before inserted to the map.
*O(log n)*. The expression (findWithDefault def k map) returns the value at key k or returns default value def when the key is not in the map.
> findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
> findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
*Deprecated.* As of version 0.5, replaced by foldr.
*O(n)*. Fold the values in the map using the given right-associative binary operator. This function is an equivalent of foldr and is present for compatibility only.
*O(n)*. Fold the values in the map using the given right-associative binary operator, such that foldr f z == foldr f z . elems.
For example,
> elems map = foldr (:) [] map
> let f a len = len + (length a)
> foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
*O(n)*. A strict version of foldr. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
the sequence minus the rightmost element, and the rightmost element

Show more results