Skip to content

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