Zulip Chat Archive
Stream: Is there code for X?
Topic: Array.pairs
Adam Topaz (Feb 06 2024 at 16:23):
Do we have something similar to the following?
def Array.pairs {α β : Type} (A : Array α) (B : Array β) : Array (α × β) := Id.run do
let mut out := #[]
for a in A do for b in B do
out := out.push (a,b)
return out
Matthew Ballard (Feb 06 2024 at 16:41):
Adam Topaz (Feb 06 2024 at 16:41):
It's not quite zip.
Matthew Ballard (Feb 06 2024 at 16:42):
Ah ok.
Adam Topaz (Feb 06 2024 at 16:42):
#eval #[1,2,3].zip #[5,6,7]
-- #[(1, 5), (2, 6), (3, 7)]
#eval #[1,2,3].pairs #[5,6,7]
-- #[(1, 5), (1, 6), (1, 7), (2, 5), (2, 6), (2, 7), (3, 5), (3, 6), (3, 7)]
Floris van Doorn (Feb 06 2024 at 16:43):
Adam Topaz (Feb 06 2024 at 16:44):
Yes, that's the one, but I would like it for arrays
Floris van Doorn (Feb 06 2024 at 16:44):
:face_palm: I should read
Adam Topaz (Feb 06 2024 at 16:45):
Although your response shows that I should name it Array.product
:)
Floris van Doorn (Feb 06 2024 at 16:45):
Yeah, and I don't think it exists already.
Last updated: May 02 2025 at 03:31 UTC