{"action":"created","issue":{"url":"https://api.github.com/repos/elm-lang/core/issues/148","labels_url":"https://api.github.com/repos/elm-lang/core/issues/148/labels{/name}","comments_url":"https://api.github.com/repos/elm-lang/core/issues/148/comments","events_url":"https://api.github.com/repos/elm-lang/core/issues/148/events","html_url":"https://github.com/elm-lang/core/issues/148","id":55741862,"number":148,"title":"Initial value in a channel ignored in foldp","user":{"login":"rehno-lindeque","id":337811,"avatar_url":"https://avatars.githubusercontent.com/u/337811?v=3","gravatar_id":"","url":"https://api.github.com/users/rehno-lindeque","html_url":"https://github.com/rehno-lindeque","followers_url":"https://api.github.com/users/rehno-lindeque/followers","following_url":"https://api.github.com/users/rehno-lindeque/following{/other_user}","gists_url":"https://api.github.com/users/rehno-lindeque/gists{/gist_id}","starred_url":"https://api.github.com/users/rehno-lindeque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rehno-lindeque/subscriptions","organizations_url":"https://api.github.com/users/rehno-lindeque/orgs","repos_url":"https://api.github.com/users/rehno-lindeque/repos","events_url":"https://api.github.com/users/rehno-lindeque/events{/privacy}","received_events_url":"https://api.github.com/users/rehno-lindeque/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-28T11:00:24Z","updated_at":"2015-01-28T13:48:01Z","closed_at":null,"body":"The initial value in a `Channel` doesn't appear in a foldp over the channel converted to a Signal.\r\n\r\n```elm\r\ntype Action = Init\r\n            | ...\r\n\r\nactions : Signal.Channel Action\r\nactions = Signal.channel Init\r\n\r\nupdate : Action -> Model -> Model\r\nupdate action state =\r\n  case Debug.log \"action\" <| action of      -- Debug.log never prints \"action: Init\"\r\n    Init -> ...\r\n\r\nmodel : Model -> Signal Action -> Signal Model\r\nmodel initialState action =\r\n  Signal.foldp update initialState action  -- Seems like the initialState here should be\r\n                                           -- combined with the initial action, either\r\n                                           -- to create the first value or to create the\r\n                                           -- first two values in the signal\r\n\r\nmain = run emptyModel (Signal.subscribe actions)\r\n\r\n```\r\n\r\nInitializing a signal with a good `initialState` is not always easy because initialization may depend on a signal coming in from a port in which case you need to do something like this:\r\n\r\n```elm\r\nport userId : Signal Int\r\n\r\nmain = run emptyModel (Signal.zip (Signal.subscribe actions) userId)\r\n```\r\n...in this case creating an initial model based on the incoming `userId` seems near impossible unless some event can be triggered (perhaps by explicitly calling `send` on the `userId` port after the widget has been initialized in order to force an update).\r\n\r\nThis might assist with issues like this one as well: https://github.com/elm-lang/core/issues/91. I'm not taking the work on promises into account, I don't know if this may be handled already in the upcoming implementation."},"comment":{"url":"https://api.github.com/repos/elm-lang/core/issues/comments/71836822","html_url":"https://github.com/elm-lang/core/issues/148#issuecomment-71836822","issue_url":"https://api.github.com/repos/elm-lang/core/issues/148","id":71836822,"user":{"login":"rehno-lindeque","id":337811,"avatar_url":"https://avatars.githubusercontent.com/u/337811?v=3","gravatar_id":"","url":"https://api.github.com/users/rehno-lindeque","html_url":"https://github.com/rehno-lindeque","followers_url":"https://api.github.com/users/rehno-lindeque/followers","following_url":"https://api.github.com/users/rehno-lindeque/following{/other_user}","gists_url":"https://api.github.com/users/rehno-lindeque/gists{/gist_id}","starred_url":"https://api.github.com/users/rehno-lindeque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rehno-lindeque/subscriptions","organizations_url":"https://api.github.com/users/rehno-lindeque/orgs","repos_url":"https://api.github.com/users/rehno-lindeque/repos","events_url":"https://api.github.com/users/rehno-lindeque/events{/privacy}","received_events_url":"https://api.github.com/users/rehno-lindeque/received_events","type":"User","site_admin":false},"created_at":"2015-01-28T13:48:01Z","updated_at":"2015-01-28T13:48:01Z","body":"Unfortunately not really - we have a button that allows admins to act on behalf of another user or as a guest (so the active user is not fixed). To be honest, I could probably change the logic so that the owner id is assigned on save rather than initialized in the widget - this is probably a better behavior.\r\n\r\nI see what you're saying with `foldp (\\_ c -> c + 1) 0`, that does make sense. I was just a little surprised... \r\n\r\nI won't spend any time on this because I'm sure you've thought about this much more deeply than I could ever hope to, but it does almost seem to me like one should be able to have some kind of `Mouse.click : DelayedSignal ()` where `foldp (\\_ c -> c + 1) 0 Mouse.click` really does start out as 0.\r\n"}}