Skip to content

Instantly share code, notes, and snippets.

@mgiacomini
Created January 15, 2019 01:12
Show Gist options
  • Save mgiacomini/208bfe6ef9dd3a6220bf116cac5d03d0 to your computer and use it in GitHub Desktop.
Save mgiacomini/208bfe6ef9dd3a6220bf116cac5d03d0 to your computer and use it in GitHub Desktop.
Bcredi miner example
path
|> CsvParser.parse(:stream)
|> Flow.from_enumerable()
|> Flow.map(&cast_contract/1) # will return {:ok, %Contract{}} | {:error, changeset}
|> Flow.map(&apply_blacklist/1) # will return {:ok, %Contract{}} | {:error, changeset} | {:filtered, reason}
|> Flow.partition(key: {:elem, 0})
|> Flow.group_by(& elem(&1, 0))
|> Flow.filter(fn
{:error, changeset} -> log_error(changeset) && false
{:filtered, reason} -> log_filtered(reason) && false
{:ok, contract} -> false
end)
|> Flow.reduce([], fn {:ok, contract}, acc -> [contract | acc] end)
|> Enum.to_list()
|> save_contracts()
|> transform_contracts() # start risk, pdd, notification updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment