Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Haskell

Idiom #170 Get map size

Set n to the number of elements stored in mymap.

This is not always equal to the map capacity.

import qualified Data.Map as Map
getMapSize :: Map.Map k v -> Int
getMapSize m = Map.size m

The eta-reduced version would simply be: getMapSize = Map.size
(def n (count mymap))

New implementation...
< >
programming-idioms.org