on main help sign in
Use deleteFirst instead of filter (#100)
commit73e7201861a752413f6d3f7eea19bce4b1291804 authorVladislav Zavialov <vlad.z.4096@gmail.com> dateTue 13 Oct 2020, 23:44 (6 years ago) parent91991f9
1 file changed+5−1
src/Data/TypeRepMap/Internal.hs+5−1
src/Data/TypeRepMap/Internal.hs+5−1
@@ -217,9 +217,13 @@ delete m
217217 -- We know we have the element, If the map has exactly one element, we can return the empty map
218218 | size m == 1 = empty
219219 -- Otherwise, filter out the element in linear time.
220− | otherwise = fromSortedTriples . filter ((/= typeFp @a) . fst3) . toSortedTriples $ m
220+ | otherwise = fromSortedTriples . deleteFirst ((== typeFp @a) . fst3) . toSortedTriples $ m
221221{-# INLINE delete #-}
222222
223+deleteFirst :: (a -> Bool) -> [a] -> [a]
224+deleteFirst _ [] = []
225+deleteFirst p (x : xs) = if p x then xs else x : deleteFirst p xs
226+
223227{- |
224228Update a value at a specific key with the result of the provided function. When
225229the key is not a member of the map, the original map is returned.