{"action":"closed","issue":{"url":"https://api.github.com/repos/javaslang/javaslang/issues/305","labels_url":"https://api.github.com/repos/javaslang/javaslang/issues/305/labels{/name}","comments_url":"https://api.github.com/repos/javaslang/javaslang/issues/305/comments","events_url":"https://api.github.com/repos/javaslang/javaslang/issues/305/events","html_url":"https://github.com/javaslang/javaslang/issues/305","id":90687417,"number":305,"title":"Improve List.partition(Predicate)","user":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/javaslang/javaslang/labels/design/refactoring","name":"design/refactoring","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/javaslang/javaslang/milestones/18","html_url":"https://github.com/javaslang/javaslang/milestones/2.0.0","labels_url":"https://api.github.com/repos/javaslang/javaslang/milestones/18/labels","id":1091674,"number":18,"title":"2.0.0","description":"","creator":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"open_issues":23,"closed_issues":25,"state":"open","created_at":"2015-04-30T20:29:59Z","updated_at":"2015-06-24T22:06:16Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2015-06-24T14:13:27Z","updated_at":"2015-06-24T22:06:16Z","closed_at":"2015-06-24T22:06:16Z","body":"Currently `List.partition()` uses two passes (modulo reverse) to split the underlying List using `filter(perdicate)` and `filter(predicate.negate())`.\r\n\r\nfunctionaljava for example partitions a List using one pass but creating intermediate objects (product/tuple):\r\n\r\n```java\r\npublic P2<List<A>, List<A>> partition(F<A, Boolean> f) {\r\n    P2<List<A>, List<A>> p2 = foldLeft(acc -> a ->\r\n        f.f(a) ? P.p(acc._1().cons(a), acc._2()) : P.p(acc._1(), acc._2().cons(a)),\r\n        P.p(nil(), nil())\r\n    );\r\n    return P.p(p2._1().reverse(), p2._2().reverse());\r\n}\r\n```\r\n\r\nScala uses mutable TraversableLike builders to build the result in one pass without using intermediate objects:\r\n\r\n```scala\r\ndef partition(p: A => Boolean): (Repr, Repr) = {\r\n    val l, r = newBuilder\r\n    for (x <- this) (if (p(x)) l else r) += x\r\n    (l.result, r.result)\r\n}\r\n```\r\n\r\nThe goal here is to use one pass and create no intermediate objects."}}