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
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'
counts : List comparable -> List (comparable, Int)
counts items =
let
counts' items =
case items of
[] -> []
(x, nx) :: [] -> [(x, nx)]
(x, nx) :: (y, ny) :: rest ->
@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
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)
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 ) )
{-| 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
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")
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
@dasch
dasch / kafka_consumer.rb
Last active January 18, 2016 09:58
Example Ruby Kafka client API
require 'kafka'
kafka_brokers = ENV.fetch("KAFKA_BROKERS").split(",")
kafka_topic = "application.events"
kafka = Kafka.new(brokers: kafka_brokers, logger: logger)
consumer = kafka.consumer(group_id: "my-consumer", autocommit: true)
consumer.subscribe(kafka_topic) do |messages|
@dasch
dasch / kafka-api.rb
Last active February 8, 2016 14:32
require "kafka"
# Current:
cluster = Kafka.new(seed_brokers: [...], client_id: "test", socket_timeout: 1)
producer = kafka.get_producer(required_acks: 2, ack_timeout: 2)
# Suggested:
cluster = Kafka::Cluster.new(seed_brokers: [...], client_id: "test", socket_timeout: 1)
producer = Kafka::Producer.new(cluster: cluster, required_acks: 2, ack_timeout: 2)