Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created May 16, 2017 23:37
Show Gist options
  • Save boxxxie/00177c0a46cd367d07815953da885440 to your computer and use it in GitHub Desktop.
Save boxxxie/00177c0a46cd367d07815953da885440 to your computer and use it in GitHub Desktop.
# first_year_maker = fn(path) ->
# fn {current_year, acc} = tuple ->
# acc_con = Map.get(acc, path)
# con = get_in(current_year, path)
# year = current_year.year_index
# case {con, acc_con} do
# {0.0, nil} -> tuple
# {nil, nil} -> tuple
# {nil, _} -> tuple
# {_, acc_con} when is_number(acc_con) -> tuple
# {con ,nil} when con > 0 -> {current_year, Map.put(acc, path, year)}
# end
# end
# end
# #cool
# rrsp_contribution = first_year_maker.([person, :accounts, :rrsp, :contribution])
# tfsa_contribution = first_year_maker.([person, :accounts, :tfsa, :contribution])
# non_reg_contribution = first_year_maker.([person, :accounts, :non_reg, :contribution])
# result_list
# |> Enum.reduce(%{}, fn cur, acc ->
# [
# rrsp_contribution,
# tfsa_contribution,
# non_reg_contribution
# ]
# |> Enum.reduce({cur, acc}, fn fun, params ->
# fun.(params)
# end)
# |> elem(1)
# end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment