How to cancel logical in the pipeline?

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 compilation error:

 ** (CompileError) iex:3: undefined function not/2 

I also tried this construct:

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

This gives me this error:

 ** (SyntaxError) iex:4: unexpected token: end 

I can do something like this that works:

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

But it is quite attractive to try to keep all this in the pipeline. Is there a way to nullify a boolean value in a pipeline?

+5
source share
1 answer

If you are using a fully functional version of a function, you can use it in the pipeline:

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

Source: https://habr.com/ru/post/1245701/


All Articles