パイプラインプレースホルダーを関数の第2引数にどのように渡すことが可能ですか?パイプラインとプレースホルダーの引数
defdefmodule CamelCase do
str = "The_Stealth_Warrior"
def to_camel_case(str) do
str
|> Regex(~r/_/, 'need_to_pass_str_argument_here', "")
|> String.split(" ")
|> Enum.map(&(String.capitalize(&1)))
|> List.to_string
end
end
ExUnit.start
defmodule TestCamelCase do
use ExUnit.Case
import CamelCase, only: [to_camel_case: 1]
test "to_camel_case" do
assert to_camel_case("The_Stealth_Warrior") == "TheStealthWarrior"
end
end
# Error
iex>
** (FunctionClauseError) no function clause matching in Regex.replace/4
(elixir) lib/regex.ex:504: Regex.replace("The_Stealth_Warrior", ~r/\W/, " ", [])
あなたがしたいことがあれば、ビルトイン['Macro.camelize/1'](https://hexdocs.pm/elixir/Macro.html#camelize/1)を使うことができます – Sheharyar
ねえ@Sheharyar、私はこれがElixirのパイプラインで練習するだけのものであることに同意します。 –