I need to create a list inside a for loop and I am having trouble doing it.
I used to have this code which works fine:
val tasksSchedules = orders.map (order => {
// Creates list of TaskSchedules
order.Product.Tasks.map(task => {
// Create TaskSchedule
})
})
However a new requirement came up where I now need to repeat the creation of the list of TaskSchedule based on a Quantity. I now have the following code:
val tasksSchedules = orders.map (order => {
// Repeats creation of TaskSchedules as many times as the value of Quantity
// Creation of list is lost with this for.
for (i <- 1 to order.Quantity) {
// Creates list of TaskSchedules
order.Product.Tasks.map(task => {
// Create TaskSchedule
})
}
})
Without the for loop everything works seamlessly. However, with the for loop no list is created which I think is to be expected. Essentially, I need a for loop construct that will enable me to iterate until a certain value and behave like the map function so I can also create a list.
Is there such a thing? Is this feasible?