How To Negate A Boolean In A Pipeline?

Viewed 2975

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?

1 Answers
Related