1

Let's say I have an operation like

Intersection[{1, 2, 3}, {1, 2, 3}, {-1, -2, -9}, SameTest -> (Abs[#1] == Abs[#2] &)]

but the arguments are being handed to me in the form of a list like

a={{1, 2, 3}, {1, 2, 3}, {-1, -2, -9}};

How do I pass a to the Intersection function above?

Intersection[a, SameTest -> (Abs[#1] == Abs[#2] &)]

doesn't work and neither does

Apply[Intersection[#, SameTest -> (Abs[#1] == Abs[#2] &)] &, a]

What should I be doing?

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Michael Stern
  • 4,695
  • 1
  • 21
  • 37

1 Answers1

5

You can use SlotSequence (##) and Apply (@@)

Intersection[##, SameTest -> (Abs[#1] == Abs[#2] &)] & @@ {{1, 2, 3}, {1, 2, 3}, {-1, -2, -9}}

It could be useful to inspect what following lines do:

a = {{1, 2, 3}, {1, 2, -3}, {-1, -2, -9}};
Sequence @@ a
## & @@ a
## & @ a
Sequence @ a
# & @@ a
# & @ a
BlacKow
  • 6,428
  • 18
  • 32
  • 1
    This works as, per the suggestion of b.gatessucks, does a2 = Apply[Sequence, a]; Intersection[a2, SameTest -> (Abs[#1] == Abs[#2] &)] – Michael Stern Jul 07 '16 at 19:47