Module

Neon.Operator

Package
purescript-neon
Repository
tfausak/purescript-neon

Every operator defined by Neon is in this module. None of them should be particularly surprising if you're already familiar with JavaScript's operators.

Operator | Fixity | Precedence | Description
-------- | ------ | ---------- | -----------
:        | left   | 8          | reverse function application
^        | right  | 7          | exponentiation
*        | left   | 6          | multiplication
/        | left   | 6          | division
%        | left   | 6          | remainder
+        | left   | 5          | addition
-        | left   | 5          | subtraction
==       | none   | 4          | equality
!=       | none   | 4          | inequality
>        | none   | 4          | greater than
>=       | none   | 4          | greater than or equal to
<        | none   | 4          | less than
<=       | none   | 4          | less than or equal to
&&       | right  | 3          | and
||       | right  | 2          | or

Note that PureScript does not allow exporting an operator (like +) without also exporting the function it's an alias of (like _add). The functions in this module are prefixed with an underscore to imply that they should not be used directly.

_add "ab" "cd" -- bad
add "cd" "ab"  -- confusing
"ab" :add "cd" -- good
"ab" + "cd"    -- better

#(:) Source

Operator alias for Neon.Operator._call (left-associative / precedence 8)

Passes an argument to a function. This is reversed function application. Since every function in Neon takes its "subject" last, it can be useful to think of this operator like . in object-oriented languages.

'a' :toUpper == toUpper 'a' -- "A"
"ab" :add "cd" == add "cd" "ab" -- "abcd"

This operator has the highest precedence so that it can be combined with other operators.

1.2 :round + 3 == (1.2 :round) + 3 -- 4

This operator is left associative. It is designed to be chained together.

'a' :toUpper :add "bc" :add "de" -- "abcde"

#(^) Source

Operator alias for Neon.Operator._power (right-associative / precedence 7)

Raises a number to a power. This is exponentiation, not exclusive or (xor). In some JavaScript implementations, this would be **.

2 ^ 3 -- 8

This operator is right-associative.

4 ^ 3 ^ 2 == 4 ^ (3 ^ 2) -- 262144

#(*) Source

Operator alias for Neon.Operator._multiply (left-associative / precedence 6)

Multiplies two numbers together.

2 * 3 -- 6

#(/) Source

Operator alias for Neon.Operator._divide (left-associative / precedence 6)

Divides a number by another number.

4 / 2 -- 2
5 / 2 -- 2
5.0 / 2.0 -- 2.5

#(%) Source

Operator alias for Neon.Operator._remainder (left-associative / precedence 6)

Finds the remainder after division.

4 % 2 -- 0
5 % 2 -- 1
5.0 % 2.0 -- 1.0
5.5 % 2.5 -- 0.5

#(+) Source

Operator alias for Neon.Operator._add (left-associative / precedence 5)

Adds two numbers together.

2 + 3 -- 5

#(-) Source

Operator alias for Neon.Operator._subtract (left-associative / precedence 5)

Subtracts one number from another.

3 - 2 -- 1

#(==) Source

Operator alias for Neon.Operator._equal (non-associative / precedence 4)

Returns true if the two things are equal.

2 == 2 -- true
2 == 3 -- false

#(!=) Source

Operator alias for Neon.Operator._notEqual (non-associative / precedence 4)

Returns true if the two things are not equal.

2 != 3 -- true
2 != 2 -- false

Note that this is different than the Prelude, which uses /= for inequality.

#(>) Source

Operator alias for Neon.Operator._greater (non-associative / precedence 4)

Returns true if the left argument is greater than the right.

2 > 1 -- true
2 > 2 -- false
2 > 3 -- false

#(>=) Source

Operator alias for Neon.Operator._greaterOrEqual (non-associative / precedence 4)

Returns true if the left argument is greater than or equal to the right.

2 >= 1 -- true
2 >= 2 -- true
2 >= 3 -- false

#(<) Source

Operator alias for Neon.Operator._less (non-associative / precedence 4)

Returns true if the left argument is less than the right.

2 < 1 -- false
2 < 2 -- false
2 < 3 -- true

#(<=) Source

Operator alias for Neon.Operator._lessOrEqual (non-associative / precedence 4)

Returns true if the left argument is less than or equal to the right.

2 <= 1 -- false
2 <= 2 -- true
2 <= 3 -- true

#(&&) Source

Operator alias for Neon.Operator._and (right-associative / precedence 3)

Returns the logical conjunction of both arguments.

true && false -- false
true && true -- true

#(||) Source

Operator alias for Neon.Operator._or (right-associative / precedence 2)

Returns the logical disjunction of both arguments.

false || false -- false
false || true -- true

#_call Source

_call :: forall b a. a -> (a -> b) -> b

#_power Source

_power :: forall a. HasPower a => a -> a -> a

#_multiply Source

_multiply :: forall a. HasMultiply a => a -> a -> a

#_divide Source

_divide :: forall a. HasDivide a => a -> a -> a

#_remainder Source

_remainder :: forall a. HasRemainder a => a -> a -> a

#_add Source

_add :: forall a. HasAdd a => a -> a -> a

#_subtract Source

_subtract :: forall a. HasSubtract a => a -> a -> a

#_equal Source

_equal :: forall a. HasEqual a => a -> a -> Boolean

#_notEqual Source

_notEqual :: forall a. HasEqual a => a -> a -> Boolean

#_greater Source

_greater :: forall a. HasGreater a => a -> a -> Boolean

#_greaterOrEqual Source

_greaterOrEqual :: forall a. HasEqual a => HasGreater a => a -> a -> Boolean

#_less Source

_less :: forall a. HasLess a => a -> a -> Boolean

#_lessOrEqual Source

_lessOrEqual :: forall a. HasEqual a => HasLess a => a -> a -> Boolean

#_and Source

_and :: forall a. HasAnd a => a -> a -> a

#_or Source

_or :: forall a. HasOr a => a -> a -> a