It is a commonplace when one needs to accumulate some data. The way I get used to do it is appending data chunks to array. But it’s a bad practice in scala, so how can I avoid it?
Share
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.
Well, there are two generic ways of dealing with accumulation: recursion and folding. Let’s look into very simple examples of each, to compute the sum of values of a list.
There are many variations on this, which handle better one case or another.