gpt4 book ai didi

elixir - 如何否定管道中的 bool 值?

转载 作者:行者123 更新时间:2023-12-04 04:32:03 24 4
gpt4 key购买 nike

考虑以下代码:

defmodule T do
def does_not_contain?(s, t) do
s |> not(String.contains?(t))
end
end

这会在编译时出现以下错误:
** (CompileError) iex:3: undefined function not/2

我也尝试过这样的构造:
defmodule T do
def does_not_contain?(s, t) do
s |> String.contains?(t) |> not
end
end

这给了我这个错误:
** (SyntaxError) iex:4: unexpected token: end

我可以做这样的事情:
defmodule T do
def does_not_contain?(s, t) do
does_contain = s |> String.contains?(t)
not(does_contain)
end
end

但是尝试将整个事情保持在管道中是非常有吸引力的。有没有办法否定管道中的 bool 值?

最佳答案

如果您使用该函数的完全限定版本,那么您可以在管道中使用它:

iex(1)> true |> Kernel.!
false
iex(2)> true |> Kernel.not
false

关于elixir - 如何否定管道中的 bool 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36201156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com