ekmett/lens

Add O(1) `Iso'`s for sets with map representations

Closed this issue · 2 comments

Data.Set.Lens: EDIT This is not O(1)

something :: Iso' (Set a) (Map a ())
something = iso Set.toMap Set.fromMap

Data.HashSet.Lens:

somethingElse :: Iso' (HashSet a) (HashMap a ())
somethingElse = iso HashSet.toMap HashSet.fromMap

We could certainly add these, but if having O(1) time complexity is important, I don't know if it's feasible to include an Iso for Set/Map conversion. As far as I know, the closest things to the Set.toMap/Set.fromMap functions you propose are fromSet/keysSet, which are O(n).

Oops, yeah, looks like only HashSet <-> HashMap is O(1).

I'm actually not in favor of adding optics converting between concrete map/set types in general, mainly because of the "why are you doing that" factor. If they are computationally free, though, it becomes "well, I guess you're not really doing anything anyway".

It's just the one Iso', then. I propose it be called Data.HashSet.Lens.hashMap.