pravnar
pravnar

Reputation: 833

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

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

Data.Set on Hackage

Upvotes: 8

Views: 223

Answers (1)

daniel gratzer
daniel gratzer

Reputation: 53891

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.

Upvotes: 12

Related Questions