Verified Commit ad958a66 authored by Camil Staps's avatar Camil Staps 🚀

Remove indexOf; export findIndex and getIndex instead

parent 1eaac224
Pipeline #8131 passed with stage
in 1 minute and 58 seconds
......@@ -200,14 +200,23 @@ findWithDefault :: !a !k !(Map k a) -> a | < k
alter :: !((Maybe a) -> Maybe a) !k !(Map k a) -> Map k a | < k
/**
* Get the position of a key in a Map so that it can be retrieved with
* {{`elemAt`}}.
* Get the index of a key in a Map so that it can be retrieved with
* {{`elemAt`}}. This gives a runtime error when the key does not exist.
* {{`getIndex`}} does the same, but uses a Maybe instead.
*/
indexOf :: !k !(Map k a) -> Maybe Int | < k
findIndex :: !k !(Map k a) -> Int | < k
/**
* Get the index of a key in a Map so that it can be retrieved with
* {{`elemAt`}}. {{`findIndex`}} does the same with a runtime error instead of
* Maybe.
*/
getIndex :: !k !(Map k a) -> Maybe Int | < k
/**
* Get the entry at a certain index. This gives a runtime error when the index
* is out of range. To get an index for a certain key, see {{`indexOf}}.
* is out of range. To get an index for a certain key, see {{`findIndex`}} and
* {{`getIndex`}}.
*/
elemAt :: !Int !(Map k a) -> (!k, !a)
......
......@@ -447,13 +447,6 @@ getIndex k m = go 0 k m
GT -> go (idx + mapSize l + 1) k r
EQ -> Just (idx + mapSize l)
indexOf :: !k !(Map k a) -> Maybe Int | < k
indexOf k Tip = Nothing
indexOf k (Bin s kx _ l r) = case lexOrd k kx of
LT -> indexOf k l
EQ -> Just (mapSize l)
GT -> ((+) (mapSize l + 1)) <$> indexOf k r
// | /O(log n)/. Retrieve an element by its /index/, i.e. by its zero-based
// index in the sequence sorted by keys. If the /index/ is out of range (less
// than zero, greater or equal to 'mapSize' of the map), 'abort` is called.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment