update monad/constantmonad definitions

This commit is contained in:
Rowan 2025-03-29 06:37:34 -05:00
parent a2e4231b06
commit c951b97dc9

View file

@ -39,9 +39,10 @@ const ConstantFunctor = {
map: constant
}
const ConstantMonad = {
const ConstantMonad = of => ({
of,
bind: constant
}
})
const PointedFunctor = of => ({
of
@ -52,10 +53,10 @@ const Applicative = {
ap
}
const Monad = {
...PointedFunctor,
const Monad = of => ({
...PointedFunctor(of),
bind
}
})
const Comonad = {
extract,
@ -65,22 +66,19 @@ const Comonad = {
export const Identity = value => create(
Value(value),
Functor,
PointedFunctor(Identity),
Monad
Monad(Identity)
)
export const Constant = value => create(
Value(value),
ConstantFunctor,
ConstantMonad,
PointedFunctor(constant)
ConstantMonad(Constant),
)
export const Ok = value => create(
Value(value),
Functor,
PointedFunctor(Ok),
Monad,
Monad(Ok),
{
isOk: true,
isErr: false,
@ -90,8 +88,7 @@ export const Ok = value => create(
export const Err = value => create(
Value(value),
ConstantFunctor,
ConstantMonad,
PointedFunctor(Err),
ConstantMonad(Err),
{
isOk: false,
isErr: true,
@ -102,8 +99,7 @@ export const Err = value => create(
export const Some = value => create(
Value(value),
Functor,
PointedFunctor(Some),
Monad,
Monad(Some),
{
isSome: true,
isNone: false,
@ -115,8 +111,7 @@ export const None = () => NoneConstant
const NoneConstant = create(
ConstantFunctor,
ConstantMonad,
PointedFunctor(None),
ConstantMonad(None),
{
isSome: false,
isNone: true,