Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation warning for Elixir 1.9.1 - Enum.chunk/2 replace with Enum.chunk_every/3. #9

Open
wants to merge 89 commits into
base: 059-building-the-grid
Choose a base branch
from

Conversation

newmanicspree
Copy link

Build:

Elixir 1.9.1 (compiled with Erlang/OTP 20)
Ubuntu 18.04

identicon.ex:

def build_grid(%Identicon.Image{hex: hex} = image) do
  grid
    |> Enum.chunk(3)
    |> Enum.map(&mirror_row/1)
    |> List.flatten
    |> Enum.with_index
end

Issues / Improvements:

  1. warning: Enum.chunk/2 is deprecated. Use Enum.chunk_every/2 instead.
  2. Also, remainder element is not discarded.
  3. Consider explicit use of anonymous function in the coursework (to connect with ecmascripters), then refactor to &mirror_row/1.

Possible solution:

Replace Enum.chunk(3) with Enum.chunk_every(3, 3, :discard)

def build_grid(%Identicon.Image{hex: hex} = image) do
  grid
    |> Enum.chunk_every(3, 3, :discard)
    |> Enum.map(fn(row) -> mirror_row(row))
    |> List.flatten
    |> Enum.with_index
end
Refactor (for learning purposes... ):
def build_grid(%Identicon.Image{hex: hex} = image) do
  grid
    |> Enum.chunk_every(3, 3, :discard)
    |> Enum.map(&mirror_row/1)
    |> List.flatten
    |> Enum.with_index
end

Nice primer course!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants