{"action":"created","issue":{"url":"https://api.github.com/repos/erikrose/more-itertools/issues/50","repository_url":"https://api.github.com/repos/erikrose/more-itertools","labels_url":"https://api.github.com/repos/erikrose/more-itertools/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/erikrose/more-itertools/issues/50/comments","events_url":"https://api.github.com/repos/erikrose/more-itertools/issues/50/events","html_url":"https://github.com/erikrose/more-itertools/pull/50","id":41743496,"number":50,"title":"Add new itertool: `side_effect()`","user":{"login":"nvie","id":83844,"avatar_url":"https://avatars.githubusercontent.com/u/83844?v=3","gravatar_id":"","url":"https://api.github.com/users/nvie","html_url":"https://github.com/nvie","followers_url":"https://api.github.com/users/nvie/followers","following_url":"https://api.github.com/users/nvie/following{/other_user}","gists_url":"https://api.github.com/users/nvie/gists{/gist_id}","starred_url":"https://api.github.com/users/nvie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvie/subscriptions","organizations_url":"https://api.github.com/users/nvie/orgs","repos_url":"https://api.github.com/users/nvie/repos","events_url":"https://api.github.com/users/nvie/events{/privacy}","received_events_url":"https://api.github.com/users/nvie/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2014-09-02T19:06:42Z","updated_at":"2016-11-18T00:51:06Z","closed_at":"2016-11-18T00:51:06Z","pull_request":{"url":"https://api.github.com/repos/erikrose/more-itertools/pulls/50","html_url":"https://github.com/erikrose/more-itertools/pull/50","diff_url":"https://github.com/erikrose/more-itertools/pull/50.diff","patch_url":"https://github.com/erikrose/more-itertools/pull/50.patch"},"body":"Passes through the iterable, but invokes a function for each item iterated over.\n\nCan be useful for lazy counting, logging, collecting data, or updating progress bars, anything un-pure.\n\n`fn` must be a function that takes a single argument.  Its return value will be discarded.\n\nExamples:\n\n```\n>>> from more_itertools import take, consume, side_effect\n>>> iterable = range(10)\n>>> iterable = side_effect(print, iterable)\n>>> consume(take(3, iterable))\n0\n1\n2\n```\n\nExample for collecting data as it streams through:\n\n```\n>>> iterable = range(10)\n>>> c = set()\n>>> iterable = side_effect(c.add, iterable)\n>>> consume(take(3, iterable))\n>>> sorted(c)\n[0, 1, 2]\n```\n\n**EDIT:** I've updated the function to support emitting side effects for chunks. This is useful because you can still process the result as a continuous stream, making chaining much easier.  It basically saves you from the ceremony of otherwise having to do this:\n\n```\n>>> iterable = range(100)\n>>> iterable = chunked(iterable, 30)\n>>> iterable = side_effect(do_something_with_chunk, iterable)\n>>> iterable = flatten(iterable)\n>>> list(iterable)\n[0, 1, 2, 3, ..., 99, 100]\n```\n"},"comment":{"url":"https://api.github.com/repos/erikrose/more-itertools/issues/comments/261417109","html_url":"https://github.com/erikrose/more-itertools/pull/50#issuecomment-261417109","issue_url":"https://api.github.com/repos/erikrose/more-itertools/issues/50","id":261417109,"user":{"login":"bbayles","id":1922815,"avatar_url":"https://avatars.githubusercontent.com/u/1922815?v=3","gravatar_id":"","url":"https://api.github.com/users/bbayles","html_url":"https://github.com/bbayles","followers_url":"https://api.github.com/users/bbayles/followers","following_url":"https://api.github.com/users/bbayles/following{/other_user}","gists_url":"https://api.github.com/users/bbayles/gists{/gist_id}","starred_url":"https://api.github.com/users/bbayles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbayles/subscriptions","organizations_url":"https://api.github.com/users/bbayles/orgs","repos_url":"https://api.github.com/users/bbayles/repos","events_url":"https://api.github.com/users/bbayles/events{/privacy}","received_events_url":"https://api.github.com/users/bbayles/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T00:51:06Z","updated_at":"2016-11-18T00:51:06Z","body":"OK, I'll close this and we'll take this back up in PR #79. Thanks!"}}
{"actor":{"display_login":"bbayles"}}