Tons of useful functions that get imported by default.
These functions only work on comparable types. This includes numbers,
characters, strings, lists of comparable things, and tuples of comparable
things. Note that tuples with 7 or more elements are not comparable; why
are your tuples so big?
Find the larger of two comparables.
Find the smaller of two comparables.
Represents the relative ordering of two things. The relations are less than, equal to, and greater than.
Compare any two comparable values. Comparable values include String, Char,
Int, Float, Time, or a list or tuple containing comparable values.
These are also the only values that work as Dict keys or Set members.
Negate a boolean value.
not True == False
not False == TrueThe logical AND operator. True if both inputs are True.
This operator short-circuits to False if the first argument is False.
The logical OR operator. True if one or both inputs are True.
This operator short-circuits to True if the first argument is True.
The exclusive-or operator. True if exactly one input is True.
Floating point division.
Exponentiation
3^2 == 9Integer division. The remainder is discarded.
Find the remainder after dividing one number by another.
7 `rem` 2 == 1
-1 `rem` 4 == -1Perform modular arithmetic.
7 % 2 == 1
-1 % 4 == 3Negate a number.
negate 42 == -42
negate -42 == 42
negate 0 == 0Take the absolute value of a number.
Take the square root of a number.
Clamps a number within a given range. With the expression
clamp 100 200 x the results are as follows:
100 if x < 100
x if 100 <= x < 200
200 if 200 <= xCalculate the logarithm of a number with a given base.
logBase 10 100 == 2
logBase 2 256 == 8An approximation of e.
An approximation of pi.
You probably do not want to use this. It takes (y/x) as the
argument, so there is no way to know whether the negative signs comes from
the y or x. Thus, the resulting angle is always between π/2 and -π/2
(in quadrants I and IV). You probably want to use atan2 instead.
This helps you find the angle of a Cartesian coordinate.
You will almost certainly want to use this instead of atan.
So atan2 y x computes atan(y/x) but also keeps track of which
quadrant the angle should really be in. The result will be between
π and -π, giving you the full range of angles.
Round a number to the nearest integer.
Floor function, rounding down.
Ceiling function, rounding up.
Truncate a number, rounding towards zero.
Convert an integer into a float.
All angle conversions result in “standard Elm angles” which happen to be radians.
Convert degrees to standard Elm angles (radians).
Convert radians to standard Elm angles (radians).
Convert turns to standard Elm angles (radians). One turn is equal to 360°.
Convert Cartesian coordinates (x,y) to polar coordinates (r,θ).
Convert polar coordinates (r,θ) to Cartesian coordinates (x,y).
Determine whether a float is an undefined or unrepresentable number. NaN stands for not a number and it is a standardized part of floating point numbers.
isNaN (0/0) == True
isNaN (sqrt -1) == True
isNaN (1/0) == False -- infinity is a number
isNaN 1 == FalseDetermine whether a float is positive or negative infinity.
isInfinite (0/0) == False
isInfinite (sqrt -1) == False
isInfinite (1/0) == True
isInfinite 1 == FalseNotice that NaN is not infinite! For float n to be finite implies that
not (isInfinite n || isNaN n) evaluates to True.
Turn any kind of value into a string. When you view the resulting string
with Text.fromString it should look just like the value it came from.
toString 42 == "42"
toString [1,2] == "[1,2]"
toString "he said, \"hi\"" == "\"he said, \\\"hi\\\"\""Put two appendable things together. This includes strings, lists, and text.
"hello" ++ "world" == "helloworld"
[1,1,2] ++ [3,5,8] == [1,1,2,3,5,8]Given a 2-tuple, returns the first value.
Given a 2-tuple, returns the second value.
Given a value, returns exactly the same value. This is called the identity function.
Create a constant function, a function that always returns the same value regardless of what input you give. It is defined as:
always a b = aIt totally ignores the second argument, so always 42 is a function that always
returns 42. When you are dealing with higher-order functions, this comes in
handy more often than you might expect. For example, creating a zeroed out list
of length ten would be:
map (always 0) [0..9]Backward function application f <| x == f x. This function is useful for
avoiding parenthesis. Consider the following code to create a text element:
leftAligned (monospace (fromString "code"))This can also be written as:
leftAligned << monospace <| fromString "code"Forward function application x |> f == f x. This function is useful
for avoiding parenthesis and writing code in a more natural way.
Consider the following code to create a pentagon:
scale 2 (move (10,10) (filled blue (ngon 5 30)))This can also be written as:
ngon 5 30
|> filled blue
|> move (10,10)
|> scale 2Function composition, passing results along in the suggested direction. For example, the following code checks if the square root of a number is odd:
not << isEven << sqrtYou can think of this operator as equivalent to the following:
(g << f) == (\x -> g (f x))So our example expands out to something like this:
\n -> not (isEven (sqrt n))Function composition, passing results along in the suggested direction. For example, the following code checks if the square root of a number is odd:
sqrt >> isEven >> notThis direction of function composition seems less pleasant than (<<) which
reads nicely in expressions like: filter (not << isRegistered) students
Flip the order of the first two arguments to a function.
Change how arguments are passed to a function. This splits paired arguments into two separate arguments.
Change how arguments are passed to a function. This combines two arguments into a single pair.