Skip to content

Instantly share code, notes, and snippets.

@dasch
Last active November 25, 2015 12:29
Show Gist options
  • Save dasch/314a836575376829e64c to your computer and use it in GitHub Desktop.
Save dasch/314a836575376829e64c to your computer and use it in GitHub Desktop.
A type system for a stream processing framework
-- A user searched or changed to a new page of search results.
type Search = { query : SearchQuery, searchId : SearchId }
-- A user clicked a search result.
type Click = { searchId : SearchId, pageId : PageId }
-- A user viewed an article.
type PageView = { pageId : PageId }
type SearchQuery = String
type PageId = String
type SearchId = String
searches : Stream SessionId Search
clicks : Stream SessionId Click
pageviews : Stream SessionId PageView
searchClickThroughs : Stream SearchQuery PageId
searchClickThroughs =
let
searchClicks : Stream SearchId (Search, Click)
searchClicks = joinBy .searchId searches clicks
in
searchClicks
|> map (\(search, click) -> { query = search.query, pageId = click.pageId })
|> keyBy .query
|> map .pageId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment