Is there any built-in function that multiplies all elements of a list with another?
i.e
let xList = [1..30]
let yList = [1..30]
would give:
[(1,1),(1,2),(1,3)..ect]
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.
This is called a cross-product or Cartesian product of lists. The easiest way to construct it is to use sequnce expressions – you can simply iterate over the two lists and yield all pairs:
If you want to use higher-order functions, then you can use
List.collect:For every value
xfrom thexList, the lambda function generates a new list (such as[(x,1); (x,2); ... (x, n)]). TheList.collectfunction then concatenates all these generated lists.