Created
May 24, 2018 12:04
-
-
Save enpedasi/fad0be9055cbbbd4a094970c680e03c0 to your computer and use it in GitHub Desktop.
Elixir Flow Window and Trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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