Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upTime.since relies on removed Signal.count #9
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jwmerrill
Nov 22, 2014
Contributor
Here's my crack at a pure Elm implementation without count, but I haven't been able to test this yet because of some other issues getting running in the new world:
since : Time -> Signal a -> Signal Bool
since t s =
let
start = map (always 1) s
stop = map (always -1) (delay t s)
delaydiff = foldp (+) 0 (merge start stop)
in
map ((/=) 0) delaydiff- Edit, changed
(==)to(/=)to get parity correct.
|
Here's my crack at a pure Elm implementation without count, but I haven't been able to test this yet because of some other issues getting running in the new world: since : Time -> Signal a -> Signal Bool
since t s =
let
start = map (always 1) s
stop = map (always -1) (delay t s)
delaydiff = foldp (+) 0 (merge start stop)
in
map ((/=) 0) delaydiff
|
evancz
referenced this issue
Nov 24, 2014
Closed
Time.since calls Signal.count which has been removed #14
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
This fix looks good to me. Can you confirm @jcollard? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jwmerrill
Nov 24, 2014
Contributor
I made some comments on why I don't yet understand how to test this at the end of this e-mail thread: https://groups.google.com/d/msg/elm-discuss/Bs4nsLVZAXM/1drQHhqYccMJ
|
I made some comments on why I don't yet understand how to test this at the end of this e-mail thread: https://groups.google.com/d/msg/elm-discuss/Bs4nsLVZAXM/1drQHhqYccMJ |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jcollard
Nov 24, 2014
Contributor
This implementation is close. At the end you should be checking (/=). I think the following version is more readable:
since : Time -> Signal a -> Signal Bool
since t s =
let
start = Signal.map (always True) s
stop = Signal.map (always False) (delay t s)
in Signal.foldp (\ n _ -> n) False (Signal.merge start stop)Also, I'll make a reply to your message on how I go about testing changes so everyone can see.
|
This implementation is close. At the end you should be checking since : Time -> Signal a -> Signal Bool
since t s =
let
start = Signal.map (always True) s
stop = Signal.map (always False) (delay t s)
in Signal.foldp (\ n _ -> n) False (Signal.merge start stop)Also, I'll make a reply to your message on how I go about testing changes so everyone can see. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jcollard
Nov 24, 2014
Contributor
Even more readable:
since : Time -> Signal a -> Signal Bool
since t s =
let initial = Signal.constant False
start = Signal.map (always True) s
stop = Signal.map (always False) (delay t s)
in Signal.mergeMany [initial, start, stop]|
Even more readable: since : Time -> Signal a -> Signal Bool
since t s =
let initial = Signal.constant False
start = Signal.map (always True) s
stop = Signal.map (always False) (delay t s)
in Signal.mergeMany [initial, start, stop] |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jwmerrill
Nov 24, 2014
Contributor
You're right about the parity of mine being reversed. I'm going to go ahead and edit it to be correct.
Your version doesn't have exactly the same behavior as the existing since. For example, if I ask for since second Mouse.clicks and then click my mouse at half-second intervals, your version will alternate between True and False, but the existing version will never become True until I stop clicking at half second intervals.
Here's an Elm 0.13 program that compares the 3 implementations:
import Mouse
import Signal
joesince t s =
let initial = Signal.constant False
start = Signal.lift (always True) s
stop = Signal.lift (always False) (delay t s)
in Signal.merges [initial, start, stop]
jasonsince t s =
let
start = Signal.lift (always 1) s
stop = Signal.lift (always -1) (delay t s)
delaydiff = foldp (+) 0 (merge start stop)
in
lift ((/=) 0) delaydiff
main = asText <~ Signal.lift3 (,,)
(since second Mouse.clicks)
(joesince second Mouse.clicks)
(jasonsince second Mouse.clicks)Try it out, and see what happens when you click your mouse regularly with a period of less than one second.
|
You're right about the parity of mine being reversed. I'm going to go ahead and edit it to be correct. Your version doesn't have exactly the same behavior as the existing Here's an Elm 0.13 program that compares the 3 implementations: import Mouse
import Signal
joesince t s =
let initial = Signal.constant False
start = Signal.lift (always True) s
stop = Signal.lift (always False) (delay t s)
in Signal.merges [initial, start, stop]
jasonsince t s =
let
start = Signal.lift (always 1) s
stop = Signal.lift (always -1) (delay t s)
delaydiff = foldp (+) 0 (merge start stop)
in
lift ((/=) 0) delaydiff
main = asText <~ Signal.lift3 (,,)
(since second Mouse.clicks)
(joesince second Mouse.clicks)
(jasonsince second Mouse.clicks)Try it out, and see what happens when you click your mouse regularly with a period of less than one second. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
You're correct. Thank you for pointing it out. |
evancz
closed this
in
c660305
Nov 24, 2014
pushed a commit
that referenced
this issue
Nov 24, 2014
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Thanks guys! :D |
jwmerrill commentedNov 22, 2014
https://github.com/elm-lang/core/blob/93bcbcde7a72581d01f0d40e8881b02e530d3c2a/src/Native/Time.js#L52