Sha256: a8f5ab2093546fc0495c053c100496fa852632660ec0d2fbfade3296c1ea00e3

Contents?: true

Size: 526 Bytes

Versions: 69

Compression:

Stored size: 526 Bytes

Contents

defmodule ETL do
  @doc """
  Transform an index into an inverted index.

  ## Examples

  iex> ETL.transform(%{"a" => ["ABILITY", "AARDVARK"], "b" => ["BALLAST", "BEAUTY"]])
  %{"ability" => "a","aardvark" =>"a","ballast" =>"b","beauty" =>"b"]
  """
  def transform(input) do
    input
    |> Map.to_list()
    |> invert
    |> List.flatten()
    |> Enum.into(%{})
  end

  defp invert(pairs) do
    Enum.map(pairs, fn {key, values} ->
      Enum.map(values, fn value -> {String.downcase(value), key} end)
    end)
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.158 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.157 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.156 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.155 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.154 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.153 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.152 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.151 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.150 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.149 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.148 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.147 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.146 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.145 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.144 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.143 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.142 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.141 tracks/elixir/exercises/etl/example.exs
trackler-2.2.1.140 tracks/elixir/exercises/etl/example.exs