Twittex v0.2.0 Twittex.Aggregator behaviour
A behaviour module for implementing stream aggregators.
Example
To create a stream aggregator, create a new module and use Twittex.Aggregator
as follow:
defmodule TagAggregator do
use Twittex.Aggregator
def map(stream) do
stream
|> Stream.flat_map(& &1["entities"]["hashtags"])
|> Stream.map(& &1["text"])
end
def reduce(tag, acc) do
Map.update(acc, tag, 1, & &1 + 1)
end
end
And this is how you may use it:
iex> "#elixir-lang" |> TagAggregator.new |> TagAggregator.run
Summary
Functions
Returns a new stream of tags matching the given query
Returns the next batch of tweets from the stream
Types
accumulator :: %{}
Functions
Returns a new stream of tags matching the given query
.
See Twittex.Client.stream/2
for more detailed information.
Specs
next(module, Stream.t, Integer.t, System.time_unit) :: %{}
Returns the next batch of tweets from the stream
.
run(aggregator, stream, print_fun \\ nil, sort_fun \\ nil, max \\ 10, frame_duration \\ 1, duration_unit \\ :seconds)
Specs
run(module, Stream.t, (any -> :ok), (any -> any), Integer.t, Integer.t, System.time_unit) :: :ok
Runs the given stream
.