Created
November 25, 2015 13:18
-
-
Save dasch/af95988a669eea983a29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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