From c951b97dc9c7f60670a93af10e591515ec82ed84 Mon Sep 17 00:00:00 2001 From: rowan Date: Sat, 29 Mar 2025 06:37:34 -0500 Subject: [PATCH] update monad/constantmonad definitions --- src/index.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/index.js b/src/index.js index 4edcfd3..183fd7d 100644 --- a/src/index.js +++ b/src/index.js @@ -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,