Consider the following code:
defmodule T do
def does_not_contain?(s, t) do
s |> not(String.contains?(t))
end
end
This gives the following error on compilation:
** (CompileError) iex:3: undefined function not/2
I also tried a construct like this:
defmodule T do
def does_not_contain?(s, t) do
s |> String.contains?(t) |> not
end
end
That gives me this error:
** (SyntaxError) iex:4: unexpected token: end
I can do something like this which works:
defmodule T do
def does_not_contain?(s, t) do
does_contain = s |> String.contains?(t)
not(does_contain)
end
end
But it's quite appealing to try to keep the whole thing in the pipeline. Is there any way to negate a boolean within the pipeline?
If you use the fully qualified version of the function then you can use it in a pipeline:
iex(1)> true |> Kernel.!
false
iex(2)> true |> Kernel.not
false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With