partition p (Bin _ x l r) = case (partition p l, partition p r) of
  ((l1, l2), (r1, r2))
    | p x       -> (join x l1 r1, merge l2 r2)
    | otherwise -> (merge l1 r1, join x l2 r2)

{----------------------------------------------------------------------
  Map
----------------------------------------------------------------------}

-- | /O(n*log n)/.
-- @'map' f s@ is the set obtained by applying @f@ to each element of @s@.
--
-- It's worth noting that the size of the result may be smaller if,
-- for some @(x,y)@, @x \/= y && f x == f y@
partition p (Bin _ x l r) = case (partition p l, partition p r) of
  ((l1, l2), (r1, r2))
    | p x       -> (join x l1 r1, merge l2 r2)
    | otherwise -> (merge l1 r1, join x l2 r2)

{----------------------------------------------------------------------
  Map
----------------------------------------------------------------------}

-- | /O(n*log n)/.
-- @'map' f s@ is the set obtained by applying @f@ to each element of @s@.
--
-- It's worth noting that the size of the result may be smaller if,
-- for some @(x,y)@, @x \/= y && f x == f y@
partition p (Bin _ x l r) = case (partition p l, partition p r) of
  ((l1, l2), (r1, r2))
    | p x       -> (join x l1 r1, merge l2 r2)
    | otherwise -> (merge l1 r1, join x l2 r2)

{----------------------------------------------------------------------
  Map
----------------------------------------------------------------------}

-- | /O(n*log n)/.
-- @'map' f s@ is the set obtained by applying @f@ to each element of @s@.
--
-- It's worth noting that the size of the result may be smaller if,
-- for some @(x,y)@, @x \/= y && f x == f y@