elm-community/basics-extra/4.0.0

NOTE: the latest version is 4.1.0

Basics.Extra

Additional basic functions.

Tuples

swap : ( a, b ) -> ( b, a )

Swaps the elements in a pair.

swap ( 1, 2 ) == ( 2, 1 )

Numbers

The maximum safe value for an integer, defined as 2^53 - 1. Anything larger than that and behaviour becomes mathematically unsound.

(maxSafeInteger + 1)
    == (maxSafeInteger + 2)
    == True

The minimum safe value for an integer, defined as -(2^53 - 1). Anything smaller than that, and behaviour becomes mathematically unsound.

(minSafeInteger - 1)
    == (minSafeInteger - 2)
    == True
isSafeInteger : Int -> Bool

Checks if a given integer is within the safe range, meaning it is between -(2^53 - 1) and 2^53 - 1.

isSafeInteger 5 == True


isSafeInteger maxSafeInteger == True


isSafeInteger (maxSafeInteger + 1) == False

Fancier Math

fractionalModBy : Float -> Float -> Float

Perform modular arithmetic involving floating point numbers.

The sign of the result is the same as the sign of the modulus in fractionalModBy modulus x.

fractionalModBy 2.5 5 == 0


fractionalModBy 2 4.5 == 0.5


fractionalModBy 2 -4.5 == 1.5


fractionalModBy -2 4.5 == -1.5

Angles

inDegrees : Float -> Float

Convert standard Elm angles (radians) to degrees.

inDegrees (turns 2) == 720


inDegrees pi == 180
inRadians : Float -> Float

Convert standard Elm angles (radians) to radians.

inRadians (degrees 90) == pi / 2


inRadians (turns 1) == 2 * pi
inTurns : Float -> Float

Convert standard Elm angles (radians) to turns. One turn is equal to 360°.

inTurns (degrees 180) == 0.5
inTurns (3 * pi) = 1.5

Higher-Order Helpers

flip : (a -> b -> c) -> b -> a -> c

Flip the order of the first two arguments to a function.

curry : (( a, b ) -> c) -> a -> b -> c

Change how arguments are passed to a function. This splits paired arguments into two separate arguments.

uncurry : (a -> b -> c) -> ( a, b ) -> c

Change how arguments are passed to a function. This combines two arguments into a single pair.