Is it possible to expand a map to a list of method arguments
In Python it is possible, eg.
Expanding tuples into arguments
I have a def map = ['a':1, 'b':2]
and a method def m(a,b)
I want to write smt like m(*map)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The spread operator (*) is used to tear a list apart into single elements. This can be used to invoke a method with multiple parameters and then spread a list into the values for the parameters.
List (lists in Groovy are closest related with tuples in Python1,2):
Map:
An importan point is that you pass the arguments by position.