Closed Janiczek closed 5 years ago
Hey @Janiczek !
This looks good to me. A few points tho:
pairOwnMembers
, everyPairOf
Maybe the name could be more specific? Im just worried that this function will get mixed up with other functions that involve lists and pairing and that it seem like "pairings" describes both equally well. Like "zip" is a kind of "pairings" it seems. Some alternative name ideas: pairOwnMembers, everyPairOf
It's called the Cartesian Product, but that might too mathy.
Maybe pairPermutations
?
Edit: Nevermind, I would assumed the permutations would include (2,1)
, not just (1,2)
.
@Chadtech
pairings
function allows me to simplify the code in this way.combinations
. What do you think?OTOH, this is not the general function for combinations -- it only computes 2-combinations.
Yeah seems like combinations
is more general. Im worried that even pairings
is too general. How would you know from the name that it doesnt include (1,2)
and (2,1)
in the output list?
Seems like the most specific name would be handshakes
. What do you think of that? Im worried about the name and the documentation being too mathematical and people not knowing what a "handshake" is (I didnt, I had to look it up, and while it was straight forward reading about it ideally looking up the term wouldnt be a necessary step).
pairsWithoutReptition
?
uniquePairs
?
FWIW I am a fan of handshakes
.
@Chadtech your uniquePairs
sound the best to me.
The bit about order not mattering ((a,b)
being the same as (b,a)
) would have to be deduced from the documentation and/or the examples, but I think there's only so much meaning you can put into a function name...
Okay. Lets do uniquePairs
then? With that change, I'd be happy to merge.
Perfect! Thanks for your PR
This is essentially doing the equivalent of the following Python loop:
It's useful eg. for Advent of Code puzzles, or any occasion where you need to check elements of a list against each other, without duplicates and without checking against self (
(x,x)
).