tracks/elixir/exercises/scale-generator/example.exs in trackler-2.2.1.109 vs tracks/elixir/exercises/scale-generator/example.exs in trackler-2.2.1.110
- old
+ new
@@ -15,11 +15,12 @@
"m": D#
"M": E
"A": F
"""
- @spec step(scale :: list(String.t()), tonic :: String.t(), step :: String.t()) :: list(String.t())
+ @spec step(scale :: list(String.t()), tonic :: String.t(), step :: String.t()) ::
+ list(String.t())
def step(scale, tonic, step) do
scale |> rotate_chromatic(tonic) |> do_step(step)
end
defp do_step([_tonic, semitone, _full_tone | _], "m"), do: semitone
@@ -64,18 +65,22 @@
defp rotate_chromatic(scale, tonic) do
scale_length = length(scale)
scale
- |> Stream.cycle
+ |> Stream.cycle()
|> Enum.take(2 * scale_length)
- |> rotate_chromatic(tonic |> String.capitalize, [])
+ |> rotate_chromatic(tonic |> String.capitalize(), [])
|> Enum.take(scale_length + 1)
end
- defp rotate_chromatic([tonic | _] = scale_from_tonic, tonic, results), do: scale_from_tonic ++ results
- defp rotate_chromatic([head | tail], tonic, results), do: rotate_chromatic(tail, tonic, results ++ [head])
+ defp rotate_chromatic([tonic | _] = scale_from_tonic, tonic, results),
+ do: scale_from_tonic ++ results
+
+ defp rotate_chromatic([head | tail], tonic, results),
+ do: rotate_chromatic(tail, tonic, results ++ [head])
+
@doc """
Certain scales will require the use of the flat version, depending on the
`tonic` (key) that begins them, which is C in the above examples.
For any of the following tonics, use the flat chromatic scale:
@@ -84,12 +89,14 @@
For all others, use the regular chromatic scale.
"""
@spec find_chromatic_scale(tonic :: String.t()) :: list(String.t())
for flat_tonic <- @flat_keys do
- def find_chromatic_scale(unquote(flat_tonic)), do: flat_chromatic_scale(unquote(flat_tonic |> String.capitalize))
+ def find_chromatic_scale(unquote(flat_tonic)),
+ do: flat_chromatic_scale(unquote(flat_tonic |> String.capitalize()))
end
+
def find_chromatic_scale(tonic) do
chromatic_scale(tonic)
end
@doc """
@@ -105,15 +112,19 @@
"""
@spec scale(tonic :: String.t(), pattern :: String.t()) :: list(String.t())
def scale(tonic, pattern) do
tonic
|> find_chromatic_scale
- |> generate_scale(pattern, [tonic |> String.capitalize])
+ |> generate_scale(pattern, [tonic |> String.capitalize()])
end
defp generate_scale(scale, pattern, results)
defp generate_scale(_scale, "", results), do: Enum.reverse(results)
- defp generate_scale(scale, <<step_amt::binary-size(1), pattern::binary>>, [last_tonic | _] = results) do
+
+ defp generate_scale(
+ scale,
+ <<step_amt::binary-size(1), pattern::binary>>,
+ [last_tonic | _] = results
+ ) do
generate_scale(scale, pattern, [step(scale, last_tonic, step_amt) | results])
end
end
-