# 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

*O(1)*. Add an element to the right end of a sequence. Mnemonic: a triangle with the single element at the pointy end.

*O(n)*. Fold the elements in the set using the given right-associative binary operator. This function is an equivalent of foldr and is present for compatibility only.
*Please note that fold will be deprecated in the future and removed.*
*O(n)*. Fold the elements in the set using the given right-associative binary operator, such that foldr f z == foldr f z . toAscList.
For example,
> toAscList set = foldr (:) [] set
*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.
*O(n)*. Fold the values in the map using the given left-associative binary operator, such that foldl f z == foldl f z . elems.
For example,
> elems = reverse . foldl (flip (:)) []
> let f len a = len + (length a)
> foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
*O(n)*. A strict version of foldl. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
*O(n)*. Fold the elements in the set using the given left-associative binary operator, such that foldl f z == foldl f z . toAscList.
For example,
> toDescList set = foldl (flip (:)) [] set
*O(n)*. A strict version of foldl. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
*O(n)*. Fold the keys and values in the map using the given right-associative binary operator, such that foldrWithKey f z == foldr (uncurry f) z . toAscList.
For example,
> keys map = foldrWithKey (\k x ks -> k:ks) [] map
> let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
> foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"
*O(n)*. A strict version of foldrWithKey. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
*Deprecated.* As of version 0.5, replaced by foldrWithKey.
*O(n)*. Fold the keys and values in the map using the given right-associative binary operator. This function is an equivalent of foldrWithKey and is present for compatibility only.
leftmost element and the rest of the sequence

*O(1)*. Add an element to the left end of a sequence. Mnemonic: a triangle with the single element at the pointy end.

*O(n)*. Fold the keys and values in the map using the given left-associative binary operator, such that foldlWithKey f z == foldl (\z' (kx, x) -> f z' kx x) z . toAscList.
For example,
> keys = reverse . foldlWithKey (\ks k x -> k:ks) []
> let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
> foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)"
*O(n)*. A strict version of foldlWithKey. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
*O(log(min(i,n-i)))*. The element at the specified position, counting from 0. The argument should thus be a non-negative integer less than the size of the sequence. If the position is out of range, index fails with an error.
*O(n)*. Fold the elements in the set using the given left-associative binary operator, such that foldl f z == foldl f z . toAscList.
For example,
> toDescList set = foldl (flip (:)) [] set
*O(n)*. A strict version of foldl. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
*O(n)*. Fold the elements in the set using the given right-associative binary operator. This function is an equivalent of foldr and is present for compatibility only.
*Please note that fold will be deprecated in the future and removed.*
*O(n)*. Fold the elements in the set using the given right-associative binary operator, such that foldr f z == foldr f z . toAscList.
For example,
> toAscList set = foldr (:) [] set
Show more results