Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
LOOKING INTENTLY INTO THE VOID

Daniel Schierbeck dasch

💭
LOOKING INTENTLY INTO THE VOID
View GitHub Profile
View consumer.rb
class Consumer
class Fetcher
def initialize(input, output)
@input, @output = input, output
@running = true
end
def run
while @running
View io_future.rb
class IoFuture
def initialize(io, &block)
@io, @block = io, block
end
def to_io
@io
end
def value
View SearchQueryIndexer.elm
module SearchQueryIndexer exposing (main)
import Stream exposing (Stream, Pipeline)
main : Pipeline
main =
Stream.readFrom "searches"
|> Stream.filter (\search -> search.resultCount > 0)
View Kafka.Consumer.elm
module Kafka.Consumer where
import Kafka
type alias Config =
{ groupId : String
, checkpointInterval : Maybe Int
, checkpointThreshold : Maybe Int
, heartbeatInterval : Int
}
View Aggregate.elm
module Aggregate exposing (..)
type alias Aggregate cmd error event state =
{ init : state
, apply : event -> state -> state
, handle : cmd -> state -> Result error event
}
type alias Coder cmd event =
{ decodeEvent : String -> Result String event
View Join.elm
impressions : Stream (ImpressionId, Impression)
clicks : Stream (ImpressionId, Click)
-- One element per key with lists of input elements.
matches : Stream (ImpressionId, (List Impression, List Click))
matches =
Stream.join impressions clicks
-- One element per input-pair match.
matches : Stream (ImpressionId, (Impression, Click))
View Foosball.Game.elm
module Foosball.Game exposing (..)
type Team = BlueTeam | RedTeam
type alias Player = String
type alias Score = Int
type Event
= PlayerAdded { team : Team, player : Player }
| PlayerRemoved { player : Player }
| ScoreAdded { team : Team, score : Score }
@dasch
dasch / Kafka.elm
Last active Aug 7, 2021
Mock stream processing API in Elm
View Kafka.elm
module Kafka exposing (..)
type alias KafkaRecord =
{ topic : String
, partition : Int
, offset : Int
, key : Maybe String
, value : Maybe String
}
View Kafka.elm
module Kafka exposing (..)
import Stream exposing (Source, Sink)
source : String -> Source String String
sink : String -> Sink String String
View App.elm
import Stream exposing (Stream, Table)
import Json.Decode
type alias Username = String
type alias Clicks = Integer
type alias Region = String
userClicks : Stream Username Clicks
userClicks = Stream.stream "user-clicks"
|> Stream.mapValue String.toInt