Skip to content

Instantly share code, notes, and snippets.

@enpedasi
Created May 24, 2018 12:04
Show Gist options
  • Save enpedasi/fad0be9055cbbbd4a094970c680e03c0 to your computer and use it in GitHub Desktop.
Save enpedasi/fad0be9055cbbbd4a094970c680e03c0 to your computer and use it in GitHub Desktop.
Elixir Flow Window and Trigger
defmodule Flowtest do
@chunk 10
def run( counts \\ 100, stages \\ 4 ) do
window = Flow.Window.global
|> Flow.Window.trigger_every(@chunk, :reset) #トリガーの定義
0..counts
|> Flow.from_enumerable
|> Flow.partition(window: window, stages: stages, hash: fn event -> {event, rem(div(event, @chunk), stages) } end )
|> Flow.reduce(fn -> [] end, fn e, acc -> [e | acc] end)
|> Flow.map_state(fn e -> Enum.reverse(e) end)
|> Flow.emit(:state)
|> Enum.to_list
|> IO.inspect charlists: :as_lists
:ok
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment