{"action":"created","issue":{"url":"https://api.github.com/repos/google/guava/issues/1071","labels_url":"https://api.github.com/repos/google/guava/issues/1071/labels{/name}","comments_url":"https://api.github.com/repos/google/guava/issues/1071/comments","events_url":"https://api.github.com/repos/google/guava/issues/1071/events","html_url":"https://github.com/google/guava/issues/1071","id":47422419,"number":1071,"title":"Introduce FluentIterable.onlyElement() and FluentIterable.onlyElement(E default)","user":{"login":"gissuebot","id":8091570,"avatar_url":"https://avatars.githubusercontent.com/u/8091570?v=3","gravatar_id":"","url":"https://api.github.com/users/gissuebot","html_url":"https://github.com/gissuebot","followers_url":"https://api.github.com/users/gissuebot/followers","following_url":"https://api.github.com/users/gissuebot/following{/other_user}","gists_url":"https://api.github.com/users/gissuebot/gists{/gist_id}","starred_url":"https://api.github.com/users/gissuebot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gissuebot/subscriptions","organizations_url":"https://api.github.com/users/gissuebot/orgs","repos_url":"https://api.github.com/users/gissuebot/repos","events_url":"https://api.github.com/users/gissuebot/events{/privacy}","received_events_url":"https://api.github.com/users/gissuebot/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/guava/labels/package%3A+collect","name":"package: collect","color":"207de5"},{"url":"https://api.github.com/repos/google/guava/labels/status%3A+research","name":"status: research","color":"bfe5bf"},{"url":"https://api.github.com/repos/google/guava/labels/type%3A+addition","name":"type: addition","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"kevinb9n","id":934551,"avatar_url":"https://avatars.githubusercontent.com/u/934551?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinb9n","html_url":"https://github.com/kevinb9n","followers_url":"https://api.github.com/users/kevinb9n/followers","following_url":"https://api.github.com/users/kevinb9n/following{/other_user}","gists_url":"https://api.github.com/users/kevinb9n/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinb9n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinb9n/subscriptions","organizations_url":"https://api.github.com/users/kevinb9n/orgs","repos_url":"https://api.github.com/users/kevinb9n/repos","events_url":"https://api.github.com/users/kevinb9n/events{/privacy}","received_events_url":"https://api.github.com/users/kevinb9n/received_events","type":"User","site_admin":false},"milestone":null,"comments":9,"created_at":"2014-10-31T17:34:06Z","updated_at":"2015-01-05T16:56:19Z","closed_at":null,"body":"_[Original issue](https://code.google.com/p/guava-libraries/issues/detail?id=1071) created by **drothmaler** on 2012-07-17 at 03:10 PM_\n\n---\n\nIt would be nice to have a FluentIterable equivalent to the Iterables.getOnlyElement methods...\n\nI recognized that there once was a \"getOnlyElement\" method in FluentIterable, but it has been removed in rev 323b48157718 - but i couldn't find any reason why.\n"},"comment":{"url":"https://api.github.com/repos/google/guava/issues/comments/68737614","html_url":"https://github.com/google/guava/issues/1071#issuecomment-68737614","issue_url":"https://api.github.com/repos/google/guava/issues/1071","id":68737614,"user":{"login":"mfulton26","id":5588957,"avatar_url":"https://avatars.githubusercontent.com/u/5588957?v=3","gravatar_id":"","url":"https://api.github.com/users/mfulton26","html_url":"https://github.com/mfulton26","followers_url":"https://api.github.com/users/mfulton26/followers","following_url":"https://api.github.com/users/mfulton26/following{/other_user}","gists_url":"https://api.github.com/users/mfulton26/gists{/gist_id}","starred_url":"https://api.github.com/users/mfulton26/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mfulton26/subscriptions","organizations_url":"https://api.github.com/users/mfulton26/orgs","repos_url":"https://api.github.com/users/mfulton26/repos","events_url":"https://api.github.com/users/mfulton26/events{/privacy}","received_events_url":"https://api.github.com/users/mfulton26/received_events","type":"User","site_admin":false},"created_at":"2015-01-05T16:56:19Z","updated_at":"2015-01-05T16:56:19Z","body":"Please correct me if I am overlooking something but aren't all of the following get\"Something\" methods' preconditions checked (either explicitly or implicitly)?\r\n1. `iterable.iterator().next()`*: there is a first element (i.e. it isn't an empty stream)\r\n2. `Iterables.getLast(iterable)`: there is a last element (i.e. it isn't an empty stream or an infinite stream)\r\n3. `Iterables.getOnlyElement(iterable)`: there is one and only one element (i.e. it isn't an empty stream or a stream with multiple elements)\r\n\r\nIn the case of getLast we can't check a java.util.Iterator to see if it is infinite or not.\r\nIf there were a way to check an iterable's precondition that it has a last element without iterating through all of the elements then I suspect that this would certainly be done but there isn't.\r\nAs such, doesn't it make sense to check all the preconditions even for getOnlyElement?\r\n\r\nIf not, then should `Iterables.getOnlyElement(iterable)` be removed from the guava library and moved to a guava-testlib?\r\n\r\n\\* as recommended in `Iterables.getFirst(Iterable<? extends T> , T)` as `Iterables.getFirst(Iterable<? extends T>)` is not provided"}}