with {:ok, user} <- Repo.insert(changeset),
{:ok, token, full_claims} <- Guardian.encode_and_sign(user, :token, claims) do
important_stuff(token, full_claims)
end
我没有简单的区别:
{:ok, user} <- Repo.insert(changeset),
{:ok, token, full_claims} <- Guardian.encode_and_sign(user, :token, claims)
important_stuff(token, full_claims)
{:ok, user} <- Repo.insert(changeset)
没有,首先with
会提高(CompileError) undefined function <-/2
。你可能是说{:ok, user} = Repo.insert(changeset)
。
Kernel.SpecialForms.with/1
在某种程度上扮演Either monad的角色。
如果RHO与LHO匹配,则转到下一个子句。否则,它将立即提早返回不匹配的RHO,并丢弃所有其他子句。如果上一个成功,则考虑应按顺序应用的几个功能。遵循这些原则。
with {:ok, text} <- File.read(name),
{:ok, words} <- MyStemmer.get_words(text),
count when in_integer(count) <- Enum.count(words),
do: IO.puts("File contained #{count}" words)
如果没有这样的文件,则将返回整个代码段,{:error, :enoent}
因为第一个子句将无法对LHO进行模式匹配。
{:ok, text} = File.read(name)
如果MatchError
没有这样的文件,它将提高。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句