Module

Neon

Package
purescript-neon
Repository
tfausak/purescript-neon

This is the top-level entry point into Neon. Typically to use Neon you would simply import this unqualified.

import Neon

If you want to avoid namespace collisions, you can import Neon qualified. It is a good idea to still import the operators unqualified, otherwise it will be annoying to use.

import Neon as N
import Neon.Operator

Here is an overview of the re-exported modules:

  • Primitive: Functions for stuff built into PureScript, like Number. This is for basics like converting between numeric types.
  • Data: Re-exports from other libraries. Neon does not define any of its own data types.
  • Effect: More re-exports. Neon also does not define any of its own effect types.
  • Class: This is why Neon exists. These classes are what separate Neon from the Prelude.
  • Helper: Things built on top of everything else. These are all nice to have but can be derived from simpler things.
  • Operator: A handful of operators for doing common tasks. Neon doesn't go overboard with operators like many other PureScript libraries.

All of Neon's documentation assumes you are familiar with the : operator. If you aren't, you should start by reading its documentation.

Re-exports from Neon.Class

#HasAdd Source

class HasAdd a  where

Represents types that can be added together. This is also known as a semigroup.

2 :add 1 -- 3
"a" :add "b" -- "ab"

Members

  • add :: a -> a -> a

Instances

#HasAnd Source

class HasAnd a  where

Represents types that can be conjoined. This is also known as logical conjunction.

true :and false -- false

Some types can't be conjoined per se but it is still useful to be able to use the && operator with them. For example, you can and two arrays together to get their intersection.

[1, 2, 3] :and [2, 3, 4] -- [2, 3]

For integers, and is bitwise.

5 :and 3 -- 3

The instance for functions is perhaps the hardest to understand. Combining two functions with and returns a new function that calls each function and then ands the results together.

even :and odd -- \ x -> (even x) :and (odd x)
(even :and odd) 3 -- false

Members

  • and :: a -> a -> a

Instances

#HasApply Source

class HasApply a  where

Represents types that can be applied from within a container. In other words, given both a function and a value in a container, apply the function to the value and return the result in a container. This is also known as an applicative functor.

[3, 4] :apply [(_ + 2), (_ * 2)] -- [5, 6, 6, 8]
Just 2 :apply (Just (_ + 1)) -- Just 3

Members

  • apply :: forall c b. a (b -> c) -> a b -> a c

Instances

#HasBottom Source

class HasBottom a  where

Represents types that have a lower bound.

bottom :: Boolean -- false
bottom :: Char -- '\0'

Members

Instances

#HasChain Source

class HasChain a  where

Represents types that can express sequential actions. This is also known as a monad.

[3, 5] :chain (\ x -> [x, x * 2]) -- [3, 6, 5, 10]

Members

  • chain :: forall c b. (b -> a c) -> a b -> a c

Instances

#HasCompare Source

class (HasEqual a, HasGreater a, HasLess a) <= HasCompare a  where

Represents type that have a total order.

2 :compare 1 -- GT
2 :compare 2 -- EQ
2 :compare 3 -- LT

Members

Instances

#HasDivide Source

class HasDivide a  where

Represents types that are divisible.

7 :divide 2 -- 3
7.0 :divide 2.0 -- 3.5

Members

Instances

#HasEqual Source

class HasEqual a  where

Represents types that can be equal to each other.

equal 1 2 -- false
equal 3 3 -- true

Members

Instances

#HasFilter Source

class HasFilter a  where

Represents types that can have elements filtered out of them.

[1, 2, 3, 4] :filter (_ > 2) -- [3, 4]

Members

Instances

#HasFromArray Source

class HasFromArray a b  where

Represents types that can be converted from an array.

fromArray [1] :: List Int -- Cons 1 Nil
fromArray [1] :: Maybe Int -- Just 1
fromArray ['a', 'b'] :: String -- "ab"

Members

Instances

#HasFromInt Source

class HasFromInt a  where

Represents types that can be converted from integers. This is typically used for enumerations.

fromInt 1 :: Maybe Bool -- Just true
fromInt 2 :: Maybe Bool -- Nothing

Members

Instances

#HasGreater Source

class HasGreater a  where

Represents types where one value can be greater than another.

2 :greater 1 -- true
1 :greater 2 -- false

Members

Instances

#HasInspect Source

class HasInspect a  where

Represents types that can be converting to a string. This is typically used for debugging. The result of inspect x should be a valid PureScript expression.

inspect 123 -- "123"
inspect (Just 123) -- "Just (123)"

The instance for functions and objects do not return valid expressions. This is because there is no way in general to generate an expression for them.

inspect identity -- "{- Function -}"
inspect {} -- "{- Object -}"

Members

Instances

#HasLess Source

class HasLess a  where

Represents types where one value can be less than another.

1 :less 2 -- true
2 :less 1 -- false

Members

Instances

#HasMap Source

class HasMap a  where

Represents types that can be mapped over. This is also know as a functor.

[1, 2, 3] :map (_ + 1) -- [2, 3, 4]

Members

  • map :: forall c b. (b -> c) -> a b -> a c

Instances

#HasMultiply Source

class HasMultiply a  where

Represents values that can be multiplied together. This is also known as a near-ring.

2 :multiply 3 -- 6

Members

Instances

#HasNot Source

class HasNot a  where

Represents types can be negated. This is known as negation.

not false -- true

The instance for functions is a little tricky. Calling not on a function returns a new function that calls the original function and then nots the result.

not even -- \ x -> not (even x)
(not even) 3 -- true

Members

Instances

#HasOne Source

class HasOne a  where

Represents types that have an multiplicative identity. This is also known as a semiring.

one :: Int -- 1
one :: Number -- 1.0

Members

Instances

#HasOr Source

class HasOr a  where

Represents types that can be disjoined. This is also known as logical disjunction.

true :or false -- true

Some types can't be disjoined per se but it is still useful to be able to use the || operator with them. For example, you can or two arrays together to get their union.

[1, 2, 3] :or [2, 3, 4] -- [1, 2, 3, 4]

For integers, or is bitwise.

5 :or 2 -- 7

The instance for functions is perhaps the hardest to understand. Combining two functions with or returns a new function that calls each function and then ors the results together.

even :or odd -- \ x -> (even x) :or (odd x)
(even :or odd) 3 -- true

Members

  • or :: a -> a -> a

Instances

#HasPower Source

class HasPower a  where

Represents types that can be exponentiated.

2 :power 3 -- 8

Members

Instances

#HasPure Source

class HasPure a  where

Represents types that allow injecting values into a container.

pure 1 :: Maybe Int -- Just 1
pure 1 :: Array Int -- [1]

Members

  • pure :: forall b. b -> a b

Instances

#HasReduce Source

class HasReduce a  where

Represents types that can be reduced to a single value. This is also known as a fold.

["wo", "rl", "d!"] :reduce (\ a e -> a + e) "hello" -- "helloworld!"

Members

  • reduce :: forall c b. (c -> b -> c) -> c -> a b -> c

Instances

#HasRemainder Source

class HasRemainder a  where

Represents types that are divisible.

7 :remainder 2 -- 1
7.0 :remainder 2.0 -- 1.0

Members

Instances

#HasSubtract Source

class HasSubtract a  where

Represents types that can be subtracted from each other.

3 :subtract 2 -- 1

Members

Instances

#HasToArray Source

class HasToArray a b  where

Represents types that can be converted to an array.

toArray (Cons 1 Nil) :: Array Int -- [1]
toArray (Just 1) :: Array Int -- [1]
toArray "ab" :: String -- ['a', 'b']

Members

Instances

#HasToInt Source

class HasToInt a  where

Represents types that can be converted to integers. This is typically used for enumerations.

toInt false -- 0

Members

Instances

#HasTop Source

class HasTop a  where

Represents types that have an upper bound.

top :: Boolean -- true
top :: Char -- '\65535'

Members

Instances

#HasTraverse Source

class HasTraverse t  where

Represents data structures that can be traversed from left to right. Unlike Reduce, these structures can be traversed while keeping their shape.

[1, 2] :traverse (\ x -> x :inspect :Just) -- Just ["1", "2"]

Members

Instances

#HasZero Source

class HasZero a  where

Represents types that have an additive identity. This is also known as a monoid.

zero :: Int -- 0
zero :: Number -- 0.0

Members

Instances

Re-exports from Neon.Data

#Unit Source

data Unit :: Type

The Unit type has a single inhabitant, called unit. It represents values with no computational content.

Unit is often used, wrapped in a monadic type constructor, as the return type of a computation where only the effects are important.

Instances

#Tuple Source

data Tuple a b

A simple product type for wrapping a pair of component values.

Constructors

Instances

#Ordering Source

data Ordering

The Ordering data type represents the three possible outcomes of comparing two values:

LT - The first value is less than the second. GT - The first value is greater than the second. EQ - The first value is equal to the second.

Constructors

Instances

#Maybe Source

data Maybe a

The Maybe type is used to represent optional values and can be seen as something like a type-safe null, where Nothing is null and Just x is the non-null value x.

Constructors

Instances

  • Functor Maybe

    The Functor instance allows functions to transform the contents of a Just with the <$> operator:

    f <$> Just x == Just (f x)
    

    Nothing values are left untouched:

    f <$> Nothing == Nothing
    
  • Apply Maybe

    The Apply instance allows functions contained within a Just to transform a value contained within a Just using the apply operator:

    Just f <*> Just x == Just (f x)
    

    Nothing values are left untouched:

    Just f <*> Nothing == Nothing
    Nothing <*> Just x == Nothing
    

    Combining Functor's <$> with Apply's <*> can be used transform a pure function to take Maybe-typed arguments so f :: a -> b -> c becomes f :: Maybe a -> Maybe b -> Maybe c:

    f <$> Just x <*> Just y == Just (f x y)
    

    The Nothing-preserving behaviour of both operators means the result of an expression like the above but where any one of the values is Nothing means the whole result becomes Nothing also:

    f <$> Nothing <*> Just y == Nothing
    f <$> Just x <*> Nothing == Nothing
    f <$> Nothing <*> Nothing == Nothing
    
  • Applicative Maybe

    The Applicative instance enables lifting of values into Maybe with the pure or return function (return is an alias for pure):

    pure x :: Maybe _ == Just x
    return x :: Maybe _ == Just x
    

    Combining Functor's <$> with Apply's <*> and Applicative's pure can be used to pass a mixture of Maybe and non-Maybe typed values to a function that does not usually expect them, by using pure for any value that is not already Maybe typed:

    f <$> Just x <*> pure y == Just (f x y)
    

    Even though pure = Just it is recommended to use pure in situations like this as it allows the choice of Applicative to be changed later without having to go through and replace Just with a new constructor.

  • Alt Maybe

    The Alt instance allows for a choice to be made between two Maybe values with the <|> operator, where the first Just encountered is taken.

    Just x <|> Just y == Just x
    Nothing <|> Just y == Just y
    Nothing <|> Nothing == Nothing
    
  • Plus Maybe

    The Plus instance provides a default Maybe value:

    empty :: Maybe _ == Nothing
    
  • Alternative Maybe

    The Alternative instance guarantees that there are both Applicative and Plus instances for Maybe.

  • Bind Maybe

    The Bind instance allows sequencing of Maybe values and functions that return a Maybe by using the >>= operator:

    Just x >>= f = f x
    Nothing >>= f = Nothing
    
  • Monad Maybe

    The Monad instance guarantees that there are both Applicative and Bind instances for Maybe. This also enables the do syntactic sugar:

    do
      x' <- x
      y' <- y
      pure (f x' y')
    

    Which is equivalent to:

    x >>= (\x' -> y >>= (\y' -> pure (f x' y')))
    
  • MonadZero Maybe
  • Extend Maybe

    The Extend instance allows sequencing of Maybe values and functions that accept a Maybe a and return a non-Maybe result using the <<= operator.

    f <<= Nothing = Nothing
    f <<= Just x = Just (f x)
    
  • Invariant Maybe
  • (Semigroup a) => Semigroup (Maybe a)

    The Semigroup instance enables use of the operator <> on Maybe values whenever there is a Semigroup instance for the type the Maybe contains. The exact behaviour of <> depends on the "inner" Semigroup instance, but generally captures the notion of appending or combining things.

    Just x <> Just y = Just (x <> y)
    Just x <> Nothing = Just x
    Nothing <> Just y = Just y
    Nothing <> Nothing = Nothing
    
  • (Semigroup a) => Monoid (Maybe a)
  • (Eq a) => Eq (Maybe a)
  • Eq1 Maybe
  • (Ord a) => Ord (Maybe a)
  • Ord1 Maybe
  • (Bounded a) => Bounded (Maybe a)
  • (Show a) => Show (Maybe a)

    The Show instance allows Maybe values to be rendered as a string with show whenever there is an Show instance for the type the Maybe contains.

#Error Source

data Error :: Type

The type of JavaScript errors

Instances

#unit Source

unit :: Unit

unit is the sole inhabitant of the Unit type.

#exception Source

exception :: String -> Error

Creates an exception with the given message.

exception "example"

Re-exports from Neon.Effect

#RANDOM Source

data RANDOM :: Effect

The RANDOM effect indicates that an Eff action may access or modify the JavaScript global random number generator, i.e. Math.random().

#Eff Source

data Eff :: Row Effect -> Type -> Type

The Eff type constructor is used to represent native effects.

See Handling Native Effects with the Eff Monad for more details.

The first type parameter is a row of effects which represents the contexts in which a computation can be run, and the second type parameter is the return type.

Instances

#EXCEPTION Source

data EXCEPTION :: Effect

This effect is used to annotate code which possibly throws exceptions

#CONSOLE Source

data CONSOLE :: Effect

The CONSOLE effect represents those computations which write to the console.

#unsafePerformEff Source

unsafePerformEff :: forall a eff. Eff eff a -> a

Run an effectful computation.

Note: use of this function can result in arbitrary side-effects.

#throw Source

throw :: forall b a. Error -> Eff (exception :: EXCEPTION | b) a

Throws an exception.

throw (exception "example"))

#runPure Source

runPure :: forall a. Pure a -> a

Run a pure computation and return its result.

#log Source

log :: forall eff. String -> Eff (console :: CONSOLE | eff) Unit

Write a message to the console.

#error Source

error :: forall eff. String -> Eff (console :: CONSOLE | eff) Unit

Write an error to the console.

#catch Source

catch :: forall b a. (Error -> Eff b a) -> Eff (exception :: EXCEPTION | b) a -> Eff b a

Catches an exception by providing and exception handler. The handler removes the EXCEPTION effect.

catch (\ x -> error x) (throw (exception "example")))

Re-exports from Neon.Helper

#withDefault Source

withDefault :: forall a. a -> Maybe a -> a

If the given value is Nothing, return the default. Otherwise return the value.

withDefault 2 Nothing -- 2
withDefault 2 (Just 1) -- 1

#while Source

while :: forall a. (a -> Boolean) -> (a -> a) -> a -> a

Keeps calling the function while the predicate is true.

1 :while (_ < 3) (_ + 1) -- 3
9 :while (_ < 3) (_ + 1) -- 9

#when Source

when :: forall a. HasPure a => Boolean -> a Unit -> a Unit

If the predicate is true, run the effect. Otherwise run an effect that does nothing.

when true [unit, unit] -- [unit, unit]
when false [unit, unit] -- [unit]

#void Source

void :: forall b a. HasMap a => a b -> a Unit

Replaces all values in the input container with unit. This is mostly useful for ignoring the value from an effect.

void [1, 2] -- [unit, unit]

#upTo Source

upTo :: forall a. HasFromInt a => HasGreater a => HasToInt a => a -> a -> Array a

Creates an array that ranges from the given lower bound down to the upper bound.

1 :upTo 3 -- [1, 2, 3]
1 :upTo 1 -- [1]
3 :upTo 1 -- []

#unsafeLog Source

unsafeLog :: forall a. String -> a -> a

Unsafely write a string to the console.

unsafeLog "unsafe!" unit -- unit (logs "unsafe!")

#unsafeCoerce Source

unsafeCoerce :: forall b a. a -> b

A wildly unsafe function that can convince the type system that any value is any type. Use this carefully!

unsafeCoerce 1 :: Number -- 1.0
unsafeCoerce 'a' :: String -- "a"

#uncurry Source

uncurry :: forall c b a. (a -> b -> c) -> (Tuple a b -> c)

Converts a regular function into one that takes a tuple.

let f x y = x + y
uncurry f (Tuple "a" "b") -- "ab"

#truncate Source

truncate :: Number -> Int

Removes the decimal part of a number and returns an integer.

truncate 1.0 -- 1
truncate 1.9 -- 1
truncate (-1.9) -- -1

#todo Source

todo :: forall a. a

A wildly unsafe function that can be used to stand in for any value.

todo :: Unit -- unit
todo :: Boolean -- ?

This should never end up in production, but it can be useful when developing a function.

#swap Source

swap :: forall b a. Tuple a b -> Tuple b a

Swaps the values in a tuple.

swap (Tuple 1 'a') -- Tuple 'a' 1

#sum Source

sum :: forall b a. HasAdd b => HasReduce a => HasZero b => a b -> b

Adds all the elements of a container together. If the container is empty, returns zero.

[1, 2, 3] :sum -- 6
([] :: Array Int) :sum -- 0
["ab", "cd", "ef"] :sum -- "abcdef"
([] :: Array String) :sum -- ""

#size Source

size :: forall b a. HasReduce a => a b -> Int

Returns the size of a container.

size [2, 3, 5] -- 3
size [] -- 0

#sign Source

sign :: forall a. HasGreater a => HasLess a => HasOne a => HasSubtract a => HasZero a => a -> a

Returns the sign of a number.

sign 2 -- 1
sign 0 -- 0
sign (-2) -- -1

#sequence Source

sequence :: forall c b a. HasApply b => HasMap b => HasTraverse a => HasPure b => a (b c) -> b (a c)

Sequences actions and collects the results.

sequence [Just 1, Just 2] -- Just [1, 2]

#reciprocal Source

reciprocal :: forall a. HasDivide a => HasOne a => a -> a

Returns the reciprocal of the value by dividing one by it.

reciprocal 2 -- 0.5

#product Source

product :: forall b a. HasMultiply b => HasOne b => HasReduce a => a b -> b

Multiplies all of the elements of a container together.

product [2, 3] -- 6
product [] -- 1

#print Source

print :: forall b a. HasInspect a => a -> Eff (console :: CONSOLE | b) Unit

Inspects a value and logs it.

print 123 -- (logs "123")

#odd Source

odd :: Int -> Boolean

Returns true if the number is odd.

odd 3 -- true
odd 4 -- false

#notEqual Source

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

Returns true if the value is not equal to the other.

2 :notEqual 1 -- true
1 :notEqual 1 -- true

#notANumber Source

notANumber :: Number -> Boolean

Returns true if the number is not a valid number. This is useful to test for nan.

notANumber 1 -- false
notANumber infinity -- false
notANumber nan -- true

#negate Source

negate :: forall a. HasSubtract a => HasZero a => a -> a

Negates the value by subtracting the value from zero.

negate 2 -- -2

#minimum Source

minimum :: forall b a. HasLess b => HasReduce a => a b -> Maybe b

Returns the least value.

minimum [2, 1, 3] -- Just 1
minimum [] -- Nothing

#min Source

min :: forall a. HasLess a => a -> a -> a

Returns the lesser value.

min 1 2 -- 1
min 2 1 -- 1

#maximum Source

maximum :: forall b a. HasGreater b => HasReduce a => a b -> Maybe b

Returns the greatest value.

maximum [1, 3, 2] -- Just 3
maximum [] -- Nothing

#max Source

max :: forall a. HasGreater a => a -> a -> a

Returns the greater value.

max 1 2 -- 2
max 2 1 -- 2

#lessOrEqual Source

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

Returns true if the value is less than or equal to the other.

2 :lessOrEqual 1 -- false
2 :lessOrEqual 2 -- true
2 :lessOrEqual 3 -- true

#infinite Source

infinite :: Number -> Boolean

Returns true if the number is infinite.

infinite infinity -- true
infinite (-infinity) -- true
infinite nan -- true
infinite 1.2 -- false

#increment Source

increment :: forall a. HasFromInt a => HasToInt a => a -> Maybe a

Increases a value by one. If the value is already the top, nothing will be returned.

increment 'a' -- Just 'b'
increment '\65535' -- Nothing

#greaterOrEqual Source

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

Returns true if the value is greater than or equal to the other.

2 :greaterOrEqual 1 -- true
2 :greaterOrEqual 2 -- true
2 :greaterOrEqual 3 -- false

#flatten Source

flatten :: forall b a. HasChain a => a (a b) -> a b

Removes a level of nesting from a container.

flatten [[1, 2], [3, 4]] -- [1, 2, 3, 4]

#even Source

even :: Int -> Boolean

Returns true if the number is even.

even 2 -- true
even 3 -- false

#empty Source

empty :: forall b a. HasReduce a => a b -> Boolean

Returns true if the container is empty.

empty [] -- true
empty [1] -- false

#downTo Source

downTo :: forall a. HasFromInt a => HasLess a => HasToInt a => a -> a -> Array a

Creates an array that ranges from the given upper bound down to the lower bound.

3 :downTo 1 -- [3, 2, 1]
1 :downTo 1 -- [1]
1 :downTo 3 -- []

#divisibleBy Source

divisibleBy :: forall a. HasEqual a => HasRemainder a => HasZero a => a -> a -> Boolean

Returns true if the number is divisible by the other.

9 :divisibleBy 3 -- true
8 :divisibleBy 3 -- false

#decrement Source

decrement :: forall a. HasFromInt a => HasToInt a => a -> Maybe a

Decreases a value by one. If the value is already the bottom, nothing will be returned.

decrement 'b' -- Just 'a'
decrement '\0' -- Nothing

#curry Source

curry :: forall c b a. (Tuple a b -> c) -> (a -> b -> c)

Converts a function that operates on tuples to a normal function.

let f (Tuple x y) = x + y
curry f "a" "b" -- "ab"

#contains Source

contains :: forall b a. HasEqual b => HasReduce a => b -> a b -> Boolean

Returns true if the container contains the element.

[1, 2, 3] :contains 2 -- true
[1, 0, 3] :contains 2 -- false

#clamp Source

clamp :: forall a. HasGreater a => HasLess a => a -> a -> a -> a

Clamps a value between some bounds. If the lower bound is greater than the upper bound, they will be swapped.

2 :clamp 3 5 -- 3
4 :clamp 3 5 -- 4
6 :clamp 3 5 -- 5
6 :clamp 5 3 -- 5

#bind Source

bind :: forall c b a. HasChain a => a b -> (b -> a c) -> a c

A version of chain with the arguments flipped. This is provided only to support desugaring do notation. It is not recommended to use explicitly.

#asTypeOf Source

asTypeOf :: forall a. a -> a -> a

A type-restricted version of always.

[] :asTypeOf [1] -- [] :: Array Int

#any Source

any :: forall b a. HasReduce a => (b -> Boolean) -> a b -> Boolean

Returns true if any of the elements in the collection pass the predicate.

[1, 2] :any (_ > 1) -- true
[1, 0] :any (_ > 1) -- false

#all Source

all :: forall b a. HasReduce a => (b -> Boolean) -> a b -> Boolean

Returns true if all of the elements in the collection pass the predicate.

[2, 3] :all (_ > 1) -- true
[2, 1] :all (_ > 1) -- false

#absoluteValue Source

absoluteValue :: forall a. HasLess a => HasSubtract a => HasZero a => a -> a

Returns the absolute value of a number.

absoluteValue (-2) -- 2
absoluteValue 3 -- 3

Re-exports from Neon.Operator

#_subtract Source

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

#_remainder Source

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

#_power Source

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

#_or Source

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

#_notEqual Source

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

#_multiply Source

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

#_lessOrEqual Source

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

#_less Source

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

#_greaterOrEqual Source

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

#_greater Source

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

#_equal Source

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

#_divide Source

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

#_call Source

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

#_and Source

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

#_add Source

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

#(||) Source

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

Returns the logical disjunction of both arguments.

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

#(^) 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._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._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._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._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._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._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._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._subtract (left-associative / precedence 5)

Subtracts one number from another.

3 - 2 -- 1

#(+) Source

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

Adds two numbers together.

2 + 3 -- 5

#(*) Source

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

Multiplies two numbers together.

2 * 3 -- 6

#(&&) 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._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._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.

Re-exports from Neon.Primitive

#toUpper Source

toUpper :: Char -> Char

Converts a character to upper case.

toUpper 'a' -- 'A'
toUpper 'A' -- 'A'

#toString Source

toString :: Char -> String

Converts a character into a string.

toString 'a' -- "a"

#toNumber Source

toNumber :: Int -> Number

Converts an integer into a number.

toNumber 1 -- 1.0

#toLower Source

toLower :: Char -> Char

Converts a character to lower case.

toLower 'A' -- 'a'
toLower 'a' -- 'a'

#round Source

round :: Number -> Int

Rounds a number to the nearest integer.

round 1.4 -- 1
round 1.6 -- 2
round 1.5 -- 2
round 2.5 -- 3

#nan Source

nan :: Number

An alias for NaN from JavaScript.

#infinity Source

infinity :: Number

An alias for Infinity from JavaScript.

#identity Source

identity :: forall a. a -> a

Returns the value it was given.

identity 1 -- 1

This is the identity function.

#floor Source

floor :: Number -> Int

Rounds a number down.

floor 1.9 -- 1

#flip Source

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

Flips the first two arguments of a function.

"a" :add "b" -- "ab"
"a" :flip add "b" -- "ba"

#finite Source

finite :: Number -> Boolean

Tests whether a number is finite or not.

finite 1.0 -- true
finite infinity -- false

#compose Source

compose :: forall c b a. (b -> c) -> (a -> b) -> (a -> c)

Returns a new function that calls the first function with the result of calling the second.

let addTwo x = x + 2
let double x = x * 2
let addTwoThenDouble x = addTwo :compose double
addTwoThenDouble 3 -- 10

This is function composition.

#ceiling Source

ceiling :: Number -> Int

Rounds a number up.

ceiling 1.1 -- 2

#always Source

always :: forall b a. a -> b -> a

Always returns the first argument.

"anything" :always 1 -- 1

This is the constant function.

#aNumber Source

aNumber :: Number -> Boolean

Tests if a number is a valid number. Returns false if the number is nan. This is necessary because nan does not equal itself.

aNumber 1.0 -- true
aNumber nan -- false
nan == nan -- false