{"action":"created","issue":{"url":"https://api.github.com/repos/cognitect-labs/transducers-js/issues/23","labels_url":"https://api.github.com/repos/cognitect-labs/transducers-js/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/cognitect-labs/transducers-js/issues/23/comments","events_url":"https://api.github.com/repos/cognitect-labs/transducers-js/issues/23/events","html_url":"https://github.com/cognitect-labs/transducers-js/issues/23","id":68554270,"number":23,"title":"Clarifying behavior of transducer/init","user":{"login":"tgriesser","id":154748,"avatar_url":"https://avatars.githubusercontent.com/u/154748?v=3","gravatar_id":"","url":"https://api.github.com/users/tgriesser","html_url":"https://github.com/tgriesser","followers_url":"https://api.github.com/users/tgriesser/followers","following_url":"https://api.github.com/users/tgriesser/following{/other_user}","gists_url":"https://api.github.com/users/tgriesser/gists{/gist_id}","starred_url":"https://api.github.com/users/tgriesser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgriesser/subscriptions","organizations_url":"https://api.github.com/users/tgriesser/orgs","repos_url":"https://api.github.com/users/tgriesser/repos","events_url":"https://api.github.com/users/tgriesser/events{/privacy}","received_events_url":"https://api.github.com/users/tgriesser/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-15T02:34:29Z","updated_at":"2015-04-15T16:29:49Z","closed_at":null,"body":"Over on [transduce](https://github.com/transduce/transduce), @kevinbeaty and I have been trying to determine the responsibility of `@@transducer/init`: [discussion](https://github.com/transduce/transduce/pull/49#issuecomment-93128552)\r\n\r\nThe purpose of `init` as a place for defining the initial value of a reduction is clear, but the question is whether it should account for any state or context the object might already retain. In short, does `init` return:\r\n \r\n1. a new empty value:\r\n\r\n```js\r\nreturn new this.constructor()\r\n```\r\n\r\n2. *the* value:\r\n\r\n```js\r\nreturn this\r\n```\r\n\r\n3. a new value retaining some notion of state:\r\n\r\n```js\r\nreturn new this.constructor(into({}, this.data)) \r\n```\r\n\r\nIt seems like the cleanest/most useful of those would be number 3, and applied to the example of Immutable.js List, it'd just be a matter of making the current value mutable/immutable:\r\n\r\n```js\r\nList.prototype['@@transducer/init'] = function() {\r\n  return this.asMutable();\r\n};\r\n\r\nList.prototype['@@transducer/step'] = function(result, arr) {\r\n  return result.set(arr[0], arr[1]);\r\n};\r\n\r\nList.prototype['@@transducer/result'] = function(obj) {\r\n  return obj.asImmutable();\r\n};\r\n```\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/cognitect-labs/transducers-js/issues/comments/93477062","html_url":"https://github.com/cognitect-labs/transducers-js/issues/23#issuecomment-93477062","issue_url":"https://api.github.com/repos/cognitect-labs/transducers-js/issues/23","id":93477062,"user":{"login":"swannodette","id":13516,"avatar_url":"https://avatars.githubusercontent.com/u/13516?v=3","gravatar_id":"","url":"https://api.github.com/users/swannodette","html_url":"https://github.com/swannodette","followers_url":"https://api.github.com/users/swannodette/followers","following_url":"https://api.github.com/users/swannodette/following{/other_user}","gists_url":"https://api.github.com/users/swannodette/gists{/gist_id}","starred_url":"https://api.github.com/users/swannodette/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swannodette/subscriptions","organizations_url":"https://api.github.com/users/swannodette/orgs","repos_url":"https://api.github.com/users/swannodette/repos","events_url":"https://api.github.com/users/swannodette/events{/privacy}","received_events_url":"https://api.github.com/users/swannodette/received_events","type":"User","site_admin":false},"created_at":"2015-04-15T16:29:49Z","updated_at":"2015-04-15T16:29:49Z","body":"@tgriesser it is not the purpose of init to return any specific thing. It takes no arguments. It should only be invoked in the case that `transduce` is invoked with 3 instead of 4 arguments."}}