Skip to content

Instantly share code, notes, and snippets.

@dasch
Created November 25, 2015 13:18
Show Gist options
  • Save dasch/af95988a669eea983a29 to your computer and use it in GitHub Desktop.
Save dasch/af95988a669eea983a29 to your computer and use it in GitHub Desktop.
module Stream where
import Dict exposing (Dict)
type alias Stream comparable v = Signal (comparable, v)
leftJoin : Stream comparable v1 -> Stream comparable v2 -> Stream comparable (v1, Maybe v2)
leftJoin stream1 stream2 =
let
buffer : Signal (Dict comparable v2)
buffer = Signal.foldp step Dict.empty stream2
step : (comparable, v2) -> Dict comparable v2 -> Dict comparable v2
step (k, v2) = Dict.insert k v2
lookup : (comparable, v1) -> Dict comparable v2 -> (comparable, (v1, Maybe v2))
lookup (k, v1) state = (k, (v1, Dict.get k state))
in
Signal.map2 lookup stream1 buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment