On Sat, 31 Dec 2016 18:59:43 -0800, pe...@mscha.org wrote: > The permutations and combinations routines both give all possibilities, > even if they're not distinct. > > > <a b b>.permutations > ((a b b) (a b b) (b a b) (b b a) (b a b) (b b a)) > > <a b b>.combinations(2) > ((a b) (a b) (b b)) > > If you want distinct permutations or combinations, you have to do > something like: > > > <a b b>.permutations.unique(:with(&[eqv])) > ((a b b) (b a b) (b b a)) > > <a b b>.combinations(2).unique(:with(&[eqv])) > ((a b) (b b)) > > This is not ideal. It would be awesome if we could do something like: > > > <a b b>.permutations(:distinct) > ((a b b) (b a b) (b b a)) > > <a b b>.combinations(2, :distinct) > ((a b) (b b)) >
To me this feels like opening a can of worms. For example, I assume you propose `:distinct` to use `eqv` for comparison, but that would mean <4> (the allomorph) and 4 (the Int) are different items and I can definitely see how some would wish for those to compare the same. We can make it take a comparator, but then we're saving just 8 characters of extra typing in a feature that's not used so commonly as to make those 8 extra chars a bother to type. > (This potentially has better performance too, depending on the > implementation.) Do you have suggestions for implementations that'd offer that? Both `.permutations` and `.unique` use lazy sequences, so `.permutations.unique[^5]` would generate just enough items to produce a list of 5. In fact, the most obvious way to implement `:distinct` is by returning a `:distinct`-less `.permutations` Seq with `.unique` call slapped on it. ------ -1 from me on this addition. YAGNI: You Ain't Gonna Need It