Oak
- Package
- purescript-oak
- Repository
- ehrenmurdick/purescript-oak
#createApp Source
createApp :: forall model msg. { init :: model, next :: msg -> model -> (msg -> Effect Unit) -> Effect Unit, update :: msg -> model -> model, view :: model -> View msg } -> App msg modelcreateApp 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 an html view.
next:
This function maps a message and model to 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 bThe 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)FunctorWithIndex Unit (Either a)Invariant (Either a)Bifunctor EitherApply (Either e)The
Applyinstance allows functions contained within aRightto transform a value contained within aRightusing the(<*>)operator:Right f <*> Right x == Right (f x)Leftvalues are left untouched:Left f <*> Right x == Left x Right f <*> Left y == Left yCombining
Functor's<$>withApply's<*>can be used to transform a pure function to takeEither-typed arguments sof :: a -> b -> cbecomesf :: 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 isLeftmeans the whole result becomesLeftalso, taking the firstLeftvalue found:f <$> Left x <*> Right y == Left x f <$> Right x <*> Left y == Left y f <$> Left x <*> Left y == Left xApplicative (Either e)The
Applicativeinstance enables lifting of values intoEitherwith thepurefunction:pure x :: Either _ _ == Right xCombining
Functor's<$>withApply's<*>andApplicative'spurecan be used to pass a mixture ofEitherand non-Eithertyped values to a function that does not usually expect them, by usingpurefor any value that is not alreadyEithertyped:f <$> Right x <*> pure y == Right (f x y)Even though
pure = Rightit is recommended to usepurein situations like this as it allows the choice ofApplicativeto be changed later without having to go through and replaceRightwith a new constructor.Alt (Either e)The
Altinstance allows for a choice to be made between twoEithervalues with the<|>operator, where the firstRightencountered is taken.Right x <|> Right y == Right x Left x <|> Right y == Right y Left x <|> Left y == Left yBind (Either e)The
Bindinstance allows sequencing ofEithervalues and functions that return anEitherby using the>>=operator:Left x >>= f = Left x Right x >>= f = f xMonad (Either e)The
Monadinstance guarantees that there are bothApplicativeandBindinstances forEither. This also enables thedosyntactic sugar:do x' <- x y' <- y pure (f x' y')Which is equivalent to:
x >>= (\x' -> y >>= (\y' -> pure (f x' y')))Extend (Either e)The
Extendinstance allows sequencing ofEithervalues and functions that accept anEitherand return a non-Eitherresult using the<<=operator.f <<= Left x = Left x f <<= Right x = Right (f (Right x))(Show a, Show b) => Show (Either a b)The
Showinstance allowsEithervalues to be rendered as a string withshowwhenever there is anShowinstance for both type theEithercan contain.(Eq a, Eq b) => Eq (Either a b)The
Eqinstance allowsEithervalues to be checked for equality with==and inequality with/=whenever there is anEqinstance for both types theEithercan contain.(Eq a) => Eq1 (Either a)(Ord a, Ord b) => Ord (Either a b)The
Ordinstance allowsEithervalues to be compared withcompare,>,>=,<and<=whenever there is anOrdinstance for both types theEithercan contain.Any
Leftvalue is considered to be less than aRightvalue.(Ord a) => Ord1 (Either a)(Bounded a, Bounded b) => Bounded (Either a b)Foldable (Either a)FoldableWithIndex Unit (Either a)Bifoldable EitherTraversable (Either a)TraversableWithIndex Unit (Either a)Bitraversable Either(Semigroup b) => Semigroup (Either a b)
#either Source
either :: forall c b a. (a -> c) -> (b -> c) -> Either a b -> cTakes 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 aThe 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 MaybeThe
Functorinstance allows functions to transform the contents of aJustwith the<$>operator:f <$> Just x == Just (f x)Nothingvalues are left untouched:f <$> Nothing == NothingApply MaybeThe
Applyinstance allows functions contained within aJustto transform a value contained within aJustusing theapplyoperator:Just f <*> Just x == Just (f x)Nothingvalues are left untouched:Just f <*> Nothing == Nothing Nothing <*> Just x == NothingCombining
Functor's<$>withApply's<*>can be used transform a pure function to takeMaybe-typed arguments sof :: a -> b -> cbecomesf :: 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 isNothingmeans the whole result becomesNothingalso:f <$> Nothing <*> Just y == Nothing f <$> Just x <*> Nothing == Nothing f <$> Nothing <*> Nothing == NothingApplicative MaybeThe
Applicativeinstance enables lifting of values intoMaybewith thepurefunction:pure x :: Maybe _ == Just xCombining
Functor's<$>withApply's<*>andApplicative'spurecan be used to pass a mixture ofMaybeand non-Maybetyped values to a function that does not usually expect them, by usingpurefor any value that is not alreadyMaybetyped:f <$> Just x <*> pure y == Just (f x y)Even though
pure = Justit is recommended to usepurein situations like this as it allows the choice ofApplicativeto be changed later without having to go through and replaceJustwith a new constructor.Alt MaybeThe
Altinstance allows for a choice to be made between twoMaybevalues with the<|>operator, where the firstJustencountered is taken.Just x <|> Just y == Just x Nothing <|> Just y == Just y Nothing <|> Nothing == NothingPlus MaybeThe
Plusinstance provides a defaultMaybevalue:empty :: Maybe _ == NothingAlternative MaybeThe
Alternativeinstance guarantees that there are bothApplicativeandPlusinstances forMaybe.Bind MaybeThe
Bindinstance allows sequencing ofMaybevalues and functions that return aMaybeby using the>>=operator:Just x >>= f = f x Nothing >>= f = NothingMonad MaybeThe
Monadinstance guarantees that there are bothApplicativeandBindinstances forMaybe. This also enables thedosyntactic sugar:do x' <- x y' <- y pure (f x' y')Which is equivalent to:
x >>= (\x' -> y >>= (\y' -> pure (f x' y')))MonadZero MaybeExtend MaybeThe
Extendinstance allows sequencing ofMaybevalues and functions that accept aMaybe aand return a non-Mayberesult using the<<=operator.f <<= Nothing = Nothing f <<= x = Just (f x)Invariant Maybe(Semigroup a) => Semigroup (Maybe a)The
Semigroupinstance enables use of the operator<>onMaybevalues whenever there is aSemigroupinstance for the type theMaybecontains. The exact behaviour of<>depends on the "inner"Semigroupinstance, 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)The
Eqinstance allowsMaybevalues to be checked for equality with==and inequality with/=whenever there is anEqinstance for the type theMaybecontains.Eq1 Maybe(Ord a) => Ord (Maybe a)The
Ordinstance allowsMaybevalues to be compared withcompare,>,>=,<and<=whenever there is anOrdinstance for the type theMaybecontains.Nothingis considered to be less than anyJustvalue.Ord1 Maybe(Bounded a) => Bounded (Maybe a)(Show a) => Show (Maybe a)The
Showinstance allowsMaybevalues to be rendered as a string withshowwhenever there is anShowinstance for the type theMaybecontains.
Re-exports from Oak.Document
Re-exports from Oak.Html
#putBuilder Source
putBuilder :: forall st. st -> Builder st Unit#getBuilder Source
getBuilder :: forall st. Builder st stRe-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
Functorinstance allows functions to transform the contents of aRightwith the<$>operator:Leftvalues are untouched: