Emoji: apply recommended tail call changes

Behavior matches previous code.

Co-authored-by: Tusooa Zhu <tusooa@kazv.moe>
This commit is contained in:
Hélène 2022-07-26 23:15:09 +02:00
parent b99f5d6183
commit 7167de592e
No known key found for this signature in database
GPG key ID: A215F2E9F1589D62

View file

@ -13,18 +13,22 @@ defmodule Pleroma.Emoji.Combinations do
# the entire emoji list in emoji-test.txt. This is safe, and, sadly, most # the entire emoji list in emoji-test.txt. This is safe, and, sadly, most
# likely sane too. # likely sane too.
defp qualification_combinations([]), do: [[]] defp qualification_combinations(codepoints) do
qualification_combinations([[]], codepoints)
defp qualification_combinations(["\uFE0F" | tail]) do
tail
|> qualification_combinations()
|> Enum.flat_map(fn x -> [x, ["\uFE0F" | x]] end)
end end
defp qualification_combinations([codepoint | tail]) do defp qualification_combinations(acc, []), do: acc
tail
|> qualification_combinations() defp qualification_combinations(acc, ["\uFE0F" | tail]) do
|> Enum.map(fn x -> [codepoint | x] end) acc
|> Enum.flat_map(fn x -> [x, x ++ ["\uFE0F"]] end)
|> qualification_combinations(tail)
end
defp qualification_combinations(acc, [codepoint | tail]) do
acc
|> Enum.map(&Kernel.++(&1, [codepoint]))
|> qualification_combinations(tail)
end end
def variate_emoji_qualification(emoji) when is_binary(emoji) do def variate_emoji_qualification(emoji) when is_binary(emoji) do