update monad/constantmonad definitions
This commit is contained in:
parent
a2e4231b06
commit
c951b97dc9
1 changed files with 12 additions and 17 deletions
29
src/index.js
29
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,
|
||||
|
|
Loading…
Add table
Reference in a new issue