Having an IndexedSeq, how to iterate it from the end to the beginning?
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.
You can call
reverseIteratorif you just want to iterate it from end to beginning. If you want to apply a map,reverseMap.foldLeftandfoldRighttraverse in opposite directions, so each can be thought of as the other on the reversed list; likewise withreduceRightandscanRight. There are a bunch oflastmethods to find things near the end instead of the beginning. Anything else, andreverse(to recreate the whole collection) or.view.reverse.whateverif you don’t want to duplicate the collection in memory. For a simpleforeach,reverseIteratorwill generally do the trick.