Created
July 26, 2015 15:47
-
-
Save boxdot/23c9e91dd07a281d3bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Time | |
currentTime : Signal Time.Time | |
currentTime = Time.every Time.second | |
main = Signal.map2 | |
(\time ls -> | |
div [] | |
[ text <| toString time | |
, ul [] <| | |
List.map (\elt -> li [] [ text <| toString elt ]) ls | |
] | |
) | |
currentTime | |
(filterPast ls) | |
-- ls = [1437923356077, 1437923356077, 1437925056077, 1437923506077] | |
ls = List.map (\n -> n * Time.second + 1437925514918 ) (range 100) | |
range n = if n == 0 then [] else n :: range (n - 1) | |
isPast : Float -> Signal Bool | |
isPast elt = Signal.map (\time -> elt <= time) currentTime | |
filterPast : List Float -> Signal (List Float) | |
filterPast ls = | |
let | |
folder = | |
Signal.map3 (\currentTime head tail -> | |
if currentTime >= head then | |
tail | |
else | |
head :: tail | |
) | |
currentTime | |
in | |
List.foldl folder (Signal.constant []) (List.map Signal.constant ls) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment