Skip to content

Instantly share code, notes, and snippets.

View dasch's full-sized avatar
💭
LOOKING INTENTLY INTO THE VOID

Daniel Schierbeck dasch

💭
LOOKING INTENTLY INTO THE VOID
View GitHub Profile
import ServiceDiscovery
import ProfileService exposing (ProfileService)
profileService : Signal ProfileService
profileService =
let
nodes : Signal (List String)
nodes = ServiceDiscovery.discover "profile"
in
Signal.map ProfileService.init nodes
with Task.andThen do
issues = Http.get "/issues.json"
milestones = Http.get "milestones.json"
in
assignMilestones (issues, milestones)
-- This would desugar to:
Task.andThen
(Http.get "/issues.json")
{-| Returns a list of repeated applications of `f`.
If `f` returns `Nothing` the iteration will stop. If it returns `Just y` then
`y` will be added to the list and the iteration will continue with `f y`.
nextYear : Int -> Maybe Int
nextYear year =
if year >= 2030 then
Nothing
else
The type annotation for `leftJoin` does not match its definition.
10│ leftJoin : Stream comparable v1 -> Stream comparable v2 -> Stream comparable (v1, Maybe v2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The type annotation is saying:
Signal ( comparable, a )
-> Signal ( comparable, b )
-> Signal ( comparable, ( a, Maybe b ) )
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)
@dasch
dasch / types.elm
Last active November 25, 2015 12:29
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
counts : List comparable -> List (comparable, Int)
counts items =
let
counts' items =
case items of
[] -> []
(x, nx) :: [] -> [(x, nx)]
(x, nx) :: (y, ny) :: rest ->
counts : List Int -> Dict Int Int
counts items =
List.map (\x -> Dict.singleton x 1) items
|> List.foldr (merge combine) Dict.empty
combine : Maybe Int -> Maybe Int -> Int
combine a b =
case (a, b) of
(Just a', Just b') -> a' + b'
clicks : Signal (Int, Int)
@dasch
dasch / git-pr
Created December 18, 2014 10:27
Open the GitHub compare page for a branch
#!/bin/bash
local_branch=$(git for-each-ref --format="%(refname:short)" $(git symbolic-ref HEAD))
remote_name=$(git config branch.$local_branch.remote)
remote_refspec=$(git config branch.$local_branch.merge)
remote_branch=${remote_refspec#refs/heads/}
remote_git_url=$(git config remote.origin.url)
remote_http_url=${remote_git_url#[email protected]:}
remote_http_url=${remote_http_url%.git}
github_url="https://github.com/$remote_http_url"