{"action":"created","issue":{"url":"https://api.github.com/repos/tshort/ReactiveBasics.jl/issues/24","repository_url":"https://api.github.com/repos/tshort/ReactiveBasics.jl","labels_url":"https://api.github.com/repos/tshort/ReactiveBasics.jl/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/tshort/ReactiveBasics.jl/issues/24/comments","events_url":"https://api.github.com/repos/tshort/ReactiveBasics.jl/issues/24/events","html_url":"https://github.com/tshort/ReactiveBasics.jl/pull/24","id":255630818,"number":24,"title":"Let the type of map and co be specified by a parameter","user":{"login":"zsoerenm","id":375486,"avatar_url":"https://avatars3.githubusercontent.com/u/375486?v=4","gravatar_id":"","url":"https://api.github.com/users/zsoerenm","html_url":"https://github.com/zsoerenm","followers_url":"https://api.github.com/users/zsoerenm/followers","following_url":"https://api.github.com/users/zsoerenm/following{/other_user}","gists_url":"https://api.github.com/users/zsoerenm/gists{/gist_id}","starred_url":"https://api.github.com/users/zsoerenm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zsoerenm/subscriptions","organizations_url":"https://api.github.com/users/zsoerenm/orgs","repos_url":"https://api.github.com/users/zsoerenm/repos","events_url":"https://api.github.com/users/zsoerenm/events{/privacy}","received_events_url":"https://api.github.com/users/zsoerenm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-09-06T14:45:59Z","updated_at":"2017-09-07T03:02:19Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/tshort/ReactiveBasics.jl/pulls/24","html_url":"https://github.com/tshort/ReactiveBasics.jl/pull/24","diff_url":"https://github.com/tshort/ReactiveBasics.jl/pull/24.diff","patch_url":"https://github.com/tshort/ReactiveBasics.jl/pull/24.patch"},"body":"Unfortunately, if you want to reset the accumulator, the last pull request only works, if `foldp` is directly called after merging the two different signals (update and reset).\r\nSince `merge` gets two different types (e.g. Update and Reset) it will look for their parent type and use that as the output type (e.g. Action). However, if you have to do a `map` before folding the result, the output will be either Update or Reset, since map is not \"type-stable\". But to reset an accumulator the given type for `foldp` must be Action.\r\nReactive.jl provides a \"typ\" parameter where you can define the output type. This feature is also provided with this pull request. Again this feels a little bit kludgy.\r\nAnother approach would be to define a \"type-stable\" map like so:\r\n\r\n```julia\r\nfunction smap{T}(f, u::Signal{T})\r\n    signal = Signal(T, f(u.value))\r\n    subscribe!(x -> push!(signal, f(x)), u)\r\n    signal\r\nend\r\n```\r\nmeaning \"stable\" - map instead of\r\n\r\n```julia\r\nfunction Base.map(f, u::Signal; init = f(u.value), typ = typeof(init))\r\n    signal = Signal(typ, init)\r\n    subscribe!(x -> push!(signal, f(x)), u)\r\n    signal\r\nend\r\n```\r\nBut with this approach, we have to implement two functions for every \"type-unstable\" function\r\n\r\nHere is an example of the current behavior:\r\n\r\n```julia\r\nusing ReactiveBasics\r\nabstract type Action{T} end\r\nstruct Update{T} <: Action{T}\r\n    val::T\r\nend\r\nstruct Reset{T} <: Action{T}\r\n    val::T\r\nend\r\nas = Signal(Update(1))\r\nbs = Signal(Reset(2))\r\nms = merge(as, bs)\r\nprintln(typeof(ms))\r\ncs = map(x -> x, ms)\r\nprintln(typeof(cs))\r\n```\r\nOutput:\r\n\r\n```\r\nReactiveBasics.Signal{Action{Int64}}\r\nReactiveBasics.Signal{Update{Int64}}\r\n```\r\nI need the last one to be Action as well"},"comment":{"url":"https://api.github.com/repos/tshort/ReactiveBasics.jl/issues/comments/327670304","html_url":"https://github.com/tshort/ReactiveBasics.jl/pull/24#issuecomment-327670304","issue_url":"https://api.github.com/repos/tshort/ReactiveBasics.jl/issues/24","id":327670304,"user":{"login":"codecov-io","id":8655789,"avatar_url":"https://avatars0.githubusercontent.com/u/8655789?v=4","gravatar_id":"","url":"https://api.github.com/users/codecov-io","html_url":"https://github.com/codecov-io","followers_url":"https://api.github.com/users/codecov-io/followers","following_url":"https://api.github.com/users/codecov-io/following{/other_user}","gists_url":"https://api.github.com/users/codecov-io/gists{/gist_id}","starred_url":"https://api.github.com/users/codecov-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codecov-io/subscriptions","organizations_url":"https://api.github.com/users/codecov-io/orgs","repos_url":"https://api.github.com/users/codecov-io/repos","events_url":"https://api.github.com/users/codecov-io/events{/privacy}","received_events_url":"https://api.github.com/users/codecov-io/received_events","type":"User","site_admin":false},"created_at":"2017-09-07T03:02:18Z","updated_at":"2017-09-07T03:02:18Z","author_association":"NONE","body":"# [Codecov](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=h1) Report\n> Merging [#24](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=desc) into [master](https://codecov.io/gh/tshort/ReactiveBasics.jl/commit/1d928d4716d4b5157e02de902dbba37a085758bb?src=pr&el=desc) will **not change** coverage.\n> The diff coverage is `100%`.\n\n[![Impacted file tree graph](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24/graphs/tree.svg?token=WuLGi5KgJU&src=pr&height=150&width=650)](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=tree)\n\n```diff\n@@          Coverage Diff          @@\n##           master    #24   +/-   ##\n=====================================\n  Coverage     100%   100%           \n=====================================\n  Files           1      1           \n  Lines          94     94           \n=====================================\n  Hits           94     94\n```\n\n\n| [Impacted Files](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=tree) | Coverage Δ | |\n|---|---|---|\n| [src/ReactiveBasics.jl](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=tree#diff-c3JjL1JlYWN0aXZlQmFzaWNzLmps) | `100% <100%> (ø)` | :arrow_up: |\n\n------\n\n[Continue to review full report at Codecov](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=continue).\n> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)\n> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`\n> Powered by [Codecov](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=footer). Last update [1d928d4...301023f](https://codecov.io/gh/tshort/ReactiveBasics.jl/pull/24?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).\n"}}
{"actor":{"display_login":"codecov-io"}}