Oak
- Package
- purescript-oak
- Repository
- ehrenmurdick/purescript-oak
#createApp Source
createApp :: forall msg model. { init :: model, next :: msg -> model -> (msg -> Effect Unit) -> Effect Unit, update :: msg -> model -> model, view :: model -> View msg } -> App msg model
createApp takes a record with a description of your Oak app. It has a few parts:
init
:
the inital model state.
view
:
Maps the current model to a view.
next
:
This function takes a message and model and returns a command. For example,
for sending an Http request when a user clicks a button. next
would be
called with the button click message and would return an Oak.Cmd
that
will execute the request.
update
:
Takes an incoming message, and the previous model state, and returns the new model state.
Re-exports from Data.Either
#Either Source
data Either a b
The Either
type is used to represent a choice between two types of value.
A common use case for Either
is error handling, where Left
is used to
carry an error value and Right
is used to carry a success value.
Constructors
Instances
Functor (Either a)
Generic (Either a b) _
Invariant (Either a)
Apply (Either e)
The
Apply
instance allows functions contained within aRight
to transform a value contained within aRight
using the(<*>)
operator:Right f <*> Right x == Right (f x)
Left
values are left untouched:Left f <*> Right x == Left f Right f <*> Left y == Left y
Combining
Functor
's<$>
withApply
's<*>
can be used to transform a pure function to takeEither
-typed arguments sof :: a -> b -> c
becomesf :: Either l a -> Either l b -> Either l c
:f <$> Right x <*> Right y == Right (f x y)
The
Left
-preserving behaviour of both operators means the result of an expression like the above but where any one of the values isLeft
means the whole result becomesLeft
also, taking the firstLeft
value found:f <$> Left x <*> Right y == Left x f <$> Right x <*> Left y == Left y f <$> Left x <*> Left y == Left x
Applicative (Either e)
The
Applicative
instance enables lifting of values intoEither
with thepure
function:pure x :: Either _ _ == Right x
Combining
Functor
's<$>
withApply
's<*>
andApplicative
'spure
can be used to pass a mixture ofEither
and non-Either
typed values to a function that does not usually expect them, by usingpure
for any value that is not alreadyEither
typed:f <$> Right x <*> pure y == Right (f x y)
Even though
pure = Right
it is recommended to usepure
in situations like this as it allows the choice ofApplicative
to be changed later without having to go through and replaceRight
with a new constructor.Alt (Either e)
The
Alt
instance allows for a choice to be made between twoEither
values with the<|>
operator, where the firstRight
encountered is taken.Right x <|> Right y == Right x Left x <|> Right y == Right y Left x <|> Left y == Left y
Bind (Either e)
The
Bind
instance allows sequencing ofEither
values and functions that return anEither
by using the>>=
operator:Left x >>= f = Left x Right x >>= f = f x
Either
's "do notation" can be understood to work like this:x :: forall e a. Either e a x = -- y :: forall e b. Either e b y = -- foo :: forall e a. (a -> b -> c) -> Either e c foo f = do x' <- x y' <- y pure (f x' y')
...which is equivalent to...
x >>= (\x' -> y >>= (\y' -> pure (f x' y')))
...and is the same as writing...
foo :: forall e a. (a -> b -> c) -> Either e c foo f = case x of Left e -> Left e Right x -> case y of Left e -> Left e Right y -> Right (f x y)
Monad (Either e)
The
Monad
instance guarantees that there are bothApplicative
andBind
instances forEither
.Extend (Either e)
The
Extend
instance allows sequencing ofEither
values and functions that accept anEither
and return a non-Either
result using the<<=
operator.f <<= Left x = Left x f <<= Right x = Right (f (Right x))
(Show a, Show b) => Show (Either a b)
The
Show
instance allowsEither
values to be rendered as a string withshow
whenever there is anShow
instance for both type theEither
can contain.(Eq a, Eq b) => Eq (Either a b)
The
Eq
instance allowsEither
values to be checked for equality with==
and inequality with/=
whenever there is anEq
instance for both types theEither
can contain.(Eq a) => Eq1 (Either a)
(Ord a, Ord b) => Ord (Either a b)
The
Ord
instance allowsEither
values to be compared withcompare
,>
,>=
,<
and<=
whenever there is anOrd
instance for both types theEither
can contain.Any
Left
value is considered to be less than aRight
value.(Ord a) => Ord1 (Either a)
(Bounded a, Bounded b) => Bounded (Either a b)
(Semigroup b) => Semigroup (Either a b)
#either Source
either :: forall a b c. (a -> c) -> (b -> c) -> Either a b -> c
Takes two functions and an Either
value, if the value is a Left
the
inner value is applied to the first function, if the value is a Right
the inner value is applied to the second function.
either f g (Left x) == f x
either f g (Right y) == g y
Re-exports from Data.Maybe
#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 aJust
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 aJust
to transform a value contained within aJust
using theapply
operator:Just f <*> Just x == Just (f x)
Nothing
values are left untouched:Just f <*> Nothing == Nothing Nothing <*> Just x == Nothing
Combining
Functor
's<$>
withApply
's<*>
can be used transform a pure function to takeMaybe
-typed arguments sof :: a -> b -> c
becomesf :: 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 isNothing
means the whole result becomesNothing
also:f <$> Nothing <*> Just y == Nothing f <$> Just x <*> Nothing == Nothing f <$> Nothing <*> Nothing == Nothing
Applicative Maybe
The
Applicative
instance enables lifting of values intoMaybe
with thepure
function:pure x :: Maybe _ == Just x
Combining
Functor
's<$>
withApply
's<*>
andApplicative
'spure
can be used to pass a mixture ofMaybe
and non-Maybe
typed values to a function that does not usually expect them, by usingpure
for any value that is not alreadyMaybe
typed:f <$> Just x <*> pure y == Just (f x y)
Even though
pure = Just
it is recommended to usepure
in situations like this as it allows the choice ofApplicative
to be changed later without having to go through and replaceJust
with a new constructor.Alt Maybe
The
Alt
instance allows for a choice to be made between twoMaybe
values with the<|>
operator, where the firstJust
encountered is taken.Just x <|> Just y == Just x Nothing <|> Just y == Just y Nothing <|> Nothing == Nothing
Plus Maybe
The
Plus
instance provides a defaultMaybe
value:empty :: Maybe _ == Nothing
Alternative Maybe
The
Alternative
instance guarantees that there are bothApplicative
andPlus
instances forMaybe
.Bind Maybe
The
Bind
instance allows sequencing ofMaybe
values and functions that return aMaybe
by using the>>=
operator:Just x >>= f = f x Nothing >>= f = Nothing
Monad Maybe
The
Monad
instance guarantees that there are bothApplicative
andBind
instances forMaybe
. This also enables thedo
syntactic sugar:do x' <- x y' <- y pure (f x' y')
Which is equivalent to:
x >>= (\x' -> y >>= (\y' -> pure (f x' y')))
Which is equivalent to:
case x of Nothing -> Nothing Just x' -> case y of Nothing -> Nothing Just y' -> Just (f x' y')
Extend Maybe
The
Extend
instance allows sequencing ofMaybe
values and functions that accept aMaybe a
and return a non-Maybe
result using the<<=
operator.f <<= Nothing = Nothing f <<= x = Just (f x)
Invariant Maybe
(Semigroup a) => Semigroup (Maybe a)
The
Semigroup
instance enables use of the operator<>
onMaybe
values whenever there is aSemigroup
instance for the type theMaybe
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)
(Semiring a) => Semiring (Maybe a)
(Eq a) => Eq (Maybe a)
The
Eq
instance allowsMaybe
values to be checked for equality with==
and inequality with/=
whenever there is anEq
instance for the type theMaybe
contains.Eq1 Maybe
(Ord a) => Ord (Maybe a)
The
Ord
instance allowsMaybe
values to be compared withcompare
,>
,>=
,<
and<=
whenever there is anOrd
instance for the type theMaybe
contains.Nothing
is considered to be less than anyJust
value.Ord1 Maybe
(Bounded a) => Bounded (Maybe a)
(Show a) => Show (Maybe a)
The
Show
instance allowsMaybe
values to be rendered as a string withshow
whenever there is anShow
instance for the type theMaybe
contains.Generic (Maybe a) _
Re-exports from Oak.Document
Re-exports from Oak.Html
Re-exports from Oak.Html.Events
#onVolumechange Source
onVolumechange :: forall msg. msg -> Attribute msg
#onTimeupdate Source
onTimeupdate :: forall msg. msg -> Attribute msg
#onRatechange Source
onRatechange :: forall msg. msg -> Attribute msg
#onProgress Source
onProgress :: forall msg. msg -> Attribute msg
#onPopstate Source
onPopstate :: forall msg. msg -> Attribute msg
#onPageshow Source
onPageshow :: forall msg. msg -> Attribute msg
#onPagehide Source
onPagehide :: forall msg. msg -> Attribute msg
#onMousewheel Source
onMousewheel :: forall msg. msg -> Attribute msg
#onMouseover Source
onMouseover :: forall msg. msg -> Attribute msg
#onMouseout Source
onMouseout :: forall msg. msg -> Attribute msg
#onMousemove Source
onMousemove :: forall msg. msg -> Attribute msg
#onMousedown Source
onMousedown :: forall msg. msg -> Attribute msg
#onLoadstart Source
onLoadstart :: forall msg. msg -> Attribute msg
#onLoadedmetadata Source
onLoadedmetadata :: forall msg. msg -> Attribute msg
#onLoadeddata Source
onLoadeddata :: forall msg. msg -> Attribute msg
#onKeypress Source
onKeypress :: forall msg. (Int -> msg) -> Attribute msg
#onHashchange Source
onHashchange :: forall msg. msg -> Attribute msg
#onDurationchange Source
onDurationchange :: forall msg. msg -> Attribute msg
#onDragstart Source
onDragstart :: forall msg. msg -> Attribute msg
#onDragover Source
onDragover :: forall msg. msg -> Attribute msg
#onDragleave Source
onDragleave :: forall msg. msg -> Attribute msg
#onDragenter Source
onDragenter :: forall msg. msg -> Attribute msg
#onDblclick Source
onDblclick :: forall msg. msg -> Attribute msg
#onCuechange Source
onCuechange :: forall msg. msg -> Attribute msg
#onCanplaythrough Source
onCanplaythrough :: forall msg. msg -> Attribute msg
#onBeforeunload Source
onBeforeunload :: forall msg. msg -> Attribute msg
#onBeforeprint Source
onBeforeprint :: forall msg. msg -> Attribute msg
#onAfterprint Source
onAfterprint :: forall msg. msg -> Attribute msg
The
Functor
instance allows functions to transform the contents of aRight
with the<$>
operator:Left
values are untouched: