{"action":"closed","issue":{"url":"https://api.github.com/repos/bodar/totallylazy/issues/27","repository_url":"https://api.github.com/repos/bodar/totallylazy","labels_url":"https://api.github.com/repos/bodar/totallylazy/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/bodar/totallylazy/issues/27/comments","events_url":"https://api.github.com/repos/bodar/totallylazy/issues/27/events","html_url":"https://github.com/bodar/totallylazy/issues/27","id":151413851,"number":27,"title":"result of repeat(callable).take(x) is constantly changing","user":{"login":"takaczapka","id":420511,"avatar_url":"https://avatars.githubusercontent.com/u/420511?v=3","gravatar_id":"","url":"https://api.github.com/users/takaczapka","html_url":"https://github.com/takaczapka","followers_url":"https://api.github.com/users/takaczapka/followers","following_url":"https://api.github.com/users/takaczapka/following{/other_user}","gists_url":"https://api.github.com/users/takaczapka/gists{/gist_id}","starred_url":"https://api.github.com/users/takaczapka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takaczapka/subscriptions","organizations_url":"https://api.github.com/users/takaczapka/orgs","repos_url":"https://api.github.com/users/takaczapka/repos","events_url":"https://api.github.com/users/takaczapka/events{/privacy}","received_events_url":"https://api.github.com/users/takaczapka/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-27T15:22:08Z","updated_at":"2016-04-27T19:25:38Z","closed_at":"2016-04-27T19:25:38Z","body":"Below test will fail.\r\n\r\n```\r\n    @Test\r\n    public void testRepeatTake() {\r\n        Sequence<Integer> seq = repeat(() -> Randoms.integers().head()).take(5);\r\n        assertThat(seq, is(seq));\r\n    }\r\n```\r\n\r\nIt's due to the fact that\r\n/com/googlecode/totallylazy/Sequences.java:438 .. take(...) \r\nis not evaluated eagerly and relies on values from (ever changing) RepeatIterator. \r\n\r\n\r\nPossible solution would be to eagerly take elements (that's what Scala does on Seq.take(x)):\r\n```\r\n    public static <T> Sequence<T> take(final Iterable<? extends T> iterable, final int count) {\r\n        List<T> ts = Iterators.toList(Iterators.take(iterable.iterator(), count));\r\n        return new Sequence<T>() {\r\n            public final Iterator<T> iterator() {\r\n                return ts.iterator();\r\n            }\r\n        };\r\n    }\r\n```\r\n\r\nSome of other functions affected: takeWhile, drop and dropWhile."}}