{"action":"created","issue":{"url":"https://api.github.com/repos/alexandru/scala-best-practices/issues/34","labels_url":"https://api.github.com/repos/alexandru/scala-best-practices/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/alexandru/scala-best-practices/issues/34/comments","events_url":"https://api.github.com/repos/alexandru/scala-best-practices/issues/34/events","html_url":"https://github.com/alexandru/scala-best-practices/issues/34","id":125772690,"number":34,"title":"Rule about updating a var for loops or conditionals","user":{"login":"JGailor","id":13087,"avatar_url":"https://avatars.githubusercontent.com/u/13087?v=3","gravatar_id":"","url":"https://api.github.com/users/JGailor","html_url":"https://github.com/JGailor","followers_url":"https://api.github.com/users/JGailor/followers","following_url":"https://api.github.com/users/JGailor/following{/other_user}","gists_url":"https://api.github.com/users/JGailor/gists{/gist_id}","starred_url":"https://api.github.com/users/JGailor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JGailor/subscriptions","organizations_url":"https://api.github.com/users/JGailor/orgs","repos_url":"https://api.github.com/users/JGailor/repos","events_url":"https://api.github.com/users/JGailor/events{/privacy}","received_events_url":"https://api.github.com/users/JGailor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-01-09T18:11:10Z","updated_at":"2016-01-12T08:17:13Z","closed_at":null,"body":"Specifically, \"2.3. SHOULD NOT update a var using loops or conditions\"\r\n\r\nI think it would be good to create some examples of when this should be done other than the toy examples provided.  A good example of this is a problem I'm wrestling with now, where I want to read the records from a relational database table in batches, and on each iteration I need to look at the last id returned from the previous result and check to see if there are any records and I should continue to iterate.   I've asked this question all over the place and haven't gotten a suggestion that fixes the problem and is performant.\r\n\r\nI was able to avoid the vars using Stream the memory utilization is just awful on large tables, but I'd like to see some guidance in a best practices document for dealing with these sort of real-world situations, or some reinforcement that this is a case where you need to observe the \"SHOULD\" of the \"SHOULD NOT\"."},"comment":{"url":"https://api.github.com/repos/alexandru/scala-best-practices/issues/comments/170834417","html_url":"https://github.com/alexandru/scala-best-practices/issues/34#issuecomment-170834417","issue_url":"https://api.github.com/repos/alexandru/scala-best-practices/issues/34","id":170834417,"user":{"login":"xavier-fernandez","id":10242025,"avatar_url":"https://avatars.githubusercontent.com/u/10242025?v=3","gravatar_id":"","url":"https://api.github.com/users/xavier-fernandez","html_url":"https://github.com/xavier-fernandez","followers_url":"https://api.github.com/users/xavier-fernandez/followers","following_url":"https://api.github.com/users/xavier-fernandez/following{/other_user}","gists_url":"https://api.github.com/users/xavier-fernandez/gists{/gist_id}","starred_url":"https://api.github.com/users/xavier-fernandez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xavier-fernandez/subscriptions","organizations_url":"https://api.github.com/users/xavier-fernandez/orgs","repos_url":"https://api.github.com/users/xavier-fernandez/repos","events_url":"https://api.github.com/users/xavier-fernandez/events{/privacy}","received_events_url":"https://api.github.com/users/xavier-fernandez/received_events","type":"User","site_admin":false},"created_at":"2016-01-12T08:17:13Z","updated_at":"2016-01-12T08:17:13Z","body":"@hellomaya \r\n\r\nYou can do that with:\r\n\r\n```scala\r\nval unionQuery = {\r\n    listToAddCollection.foldLeft(List())(\r\n          (unionQuery, queryToAdd) =>\r\n             unionQuery ++ queryToAdd\r\n   )\r\n}\r\n```"}}