Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Data.Set supply elems as well as toList?

Tags:

haskell

set

In the source, we have elems = toList. Why do we need both functions?

Data.Set on Hackage

like image 437
pravnar Avatar asked Oct 19 '13 03:10

pravnar


1 Answers

It's part of the pattern that most collections provide. In the case of set, there are no keys, so elems = toList. However with things like a Map, toList returns an association list vs elems which just returns the values.

So the seeming redundancy is to provide a consistent API with other collections like Map, IntSet Arrays and IntMap.

like image 182
Daniel Gratzer Avatar answered Oct 18 '22 02:10

Daniel Gratzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!