-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename MultiSet to Bag, MultiDict => MultiMap? #17
Comments
The name Is |
Bag does appear to be an established name: https://en.wikipedia.org/wiki/Set_(abstract_data_type)#Multiset but you're likely right, that MultiSet is more commonly used, I'm not sure. That's too bad about the |
This does raise the question of why we need a |
I’m in favor of deprecating |
Do we need both a counted set and a set which retains original copies? Although both can occasionally be useful, I would tend to say that most uses of the latter would just as well be served by a MultiMap. It's only the former that is really awkward and inefficient. However, I don't think the counted set is very intuitively a Also 👎 to introducing a name collision between the old |
The I prefer |
Thanks @Ichoran ! Some points:
So if I interpret correctly, you're saying that Now for some quick points for the name change:
|
You can't get elements out of sets, and if you manage to, you do get one that you put in (if you put in duplicates, you obviously only get one of them out). The bag is acting more like a bank: you deposit an item, and you get out an equivalent item, but not necessarily the one you put in. (Though it's weirder if counted--it will give you back the same item multiple times, rather than drawing separate instances from a vault of available instances.) The point about the length of the name is a good one, though. That may be important enough to override all the other concerns. |
Oh, also, next time my groceries end up packed all jumbled up/unstructured, I will remind myself that it is because they were put in a bag 😂 |
I’m convinced that |
@julienrf I also don't think KeyBag is an improvement over MultiDict. |
Copied from #98 TLDR; I think it should be named I think it may make the most sense to rename
|
@er1c I agree that MultiMap and MultiSet (I would prefer Bag) should be abstract data types (akin to Seq, Map, Set). I also tried to point this out in #25. I think that everyone agrees that 'MultiDict' is much worse a name than MultiMap, but it was named that way to avoid collisions with the stdlib implementation. I agree that there would be valid usecases for MultiMaps where the underlying value collection is a Set or a Seq or even a Bag. Perhaps the best way to achieve this would be to utilize the existing Iterable Factories so that users can pass in whatever kind of collection they like? Maybe this is possible: trait MultiMap[K, V, C[_]] { ... }
object MultiMap {
def withValuesIn[C[_]](factory: IterableFactory[C]): Factory[(K, V), MultiMap[K, V, C] = ???
}
// user code
MultiMap.withValuesIn(List)(1 -> 1, 1 -> 2, 1 -> 3) Perhaps some reasonable default value collection should be chosen (probably Set?) so that users can still initialize a MultiMap without specifying the value: object MultiMap extends Factory[(K, V), MultiMap[K, V, Set]] {
/// implement factory...
// additional method
def withValuesIn[C[_]](factory: IterableFactory[C]): Factory[(K, V), MultiMap[K, V, C] = ???
}
// user code:
MultiMap(1 -> 1, 1 -> 2) // MultiMap[Int, Int, Set]
MultiMap.withValuesIn(List)(1 -> 1, 1 -> 2) // MultiMap[Int, Int, List]
MultiMap.withValuesIn(Bag)(1 -> 1, 1 -> 2) // MultiMap[Int, Int, Bag] If that route is taken then I would suggest making a static factory for each of the most common collection types so that we avoid allocating on each MultiMap creation, so: object MultiMap extends Factory[(K, V), MultiMap[K, V, Set]] {
/// implement factory...
// additional method
private final val ListMultiMapFactory = ???
private final vall SetMultiMapFactory = ???
private final val VectorMultiMapFactory = ???
def withValuesIn[C[_]](factory: IterableFactory[C]): Factory[(K, V), MultiMap[K, V, C] = factory match {
case List => ListMultiMapFactory
case Vector => VectorMultiMapFactory
case Set => SetMultiMapFactory
case other => new MultiMapFactory(other)
}
} Care should also ideally be taken to design the api so that users that just want to use the default collection don't have to specify the higher kinded type parameter everywhere. This is the same principle that was applied to the new views which make them much more ergonomic (so, Or maybe I'm just over complicating things, just giving ideas. |
This is exactly what I was thinking. I think the only other option is My brain starts going into CanBuildFrom implicits when thinking about it, so I probably need to brush up more on the 2.13 collections to see a better builder strategy :) |
abandoned draft PR: #24 |
|
Bag
is a lot less verbose thanMultiSet
, andMultiDict
is also pretty awkward to try and say aloud.The text was updated successfully, but these errors were encountered: