Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the remainder operator for Elm

Tags:

elm

I have this function

result = 
  add 1 2 |> \a -> a % 2 == 0)

and I am getting this error

Elm does not use (%) as the remainder operator

When I look at the docs I see I can use modBy, so I tried this.

result =
   add 1 2 |> (\a -> a modBy 2 == 0)

But that gives me the following error.

This function cannot handle the argument sent through the (|>) pipe:
like image 816
Landon Call Avatar asked Mar 03 '23 05:03

Landon Call


1 Answers

The % operator was removed in 0.19 to reduce the confusion between rem and mod.

modBy and remainderBy are regular functions. You use them like:

result = add 1 2 |> (\a -> modBy 2 a == 0)

or, if you prefer a functional composition variant of the code:

result = add 1 2 |> modBy 2 >> (==) 0

As a historical note, there used to be a way to call functions infix using backticks notation:

 a `modBy` 2

but this was removed in 0.18

like image 52
pdamoc Avatar answered Mar 07 '23 15:03

pdamoc