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
|
map: constant
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConstantMonad = {
|
const ConstantMonad = of => ({
|
||||||
|
of,
|
||||||
bind: constant
|
bind: constant
|
||||||
}
|
})
|
||||||
|
|
||||||
const PointedFunctor = of => ({
|
const PointedFunctor = of => ({
|
||||||
of
|
of
|
||||||
|
@ -52,10 +53,10 @@ const Applicative = {
|
||||||
ap
|
ap
|
||||||
}
|
}
|
||||||
|
|
||||||
const Monad = {
|
const Monad = of => ({
|
||||||
...PointedFunctor,
|
...PointedFunctor(of),
|
||||||
bind
|
bind
|
||||||
}
|
})
|
||||||
|
|
||||||
const Comonad = {
|
const Comonad = {
|
||||||
extract,
|
extract,
|
||||||
|
@ -65,22 +66,19 @@ const Comonad = {
|
||||||
export const Identity = value => create(
|
export const Identity = value => create(
|
||||||
Value(value),
|
Value(value),
|
||||||
Functor,
|
Functor,
|
||||||
PointedFunctor(Identity),
|
Monad(Identity)
|
||||||
Monad
|
|
||||||
)
|
)
|
||||||
|
|
||||||
export const Constant = value => create(
|
export const Constant = value => create(
|
||||||
Value(value),
|
Value(value),
|
||||||
ConstantFunctor,
|
ConstantFunctor,
|
||||||
ConstantMonad,
|
ConstantMonad(Constant),
|
||||||
PointedFunctor(constant)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
export const Ok = value => create(
|
export const Ok = value => create(
|
||||||
Value(value),
|
Value(value),
|
||||||
Functor,
|
Functor,
|
||||||
PointedFunctor(Ok),
|
Monad(Ok),
|
||||||
Monad,
|
|
||||||
{
|
{
|
||||||
isOk: true,
|
isOk: true,
|
||||||
isErr: false,
|
isErr: false,
|
||||||
|
@ -90,8 +88,7 @@ export const Ok = value => create(
|
||||||
export const Err = value => create(
|
export const Err = value => create(
|
||||||
Value(value),
|
Value(value),
|
||||||
ConstantFunctor,
|
ConstantFunctor,
|
||||||
ConstantMonad,
|
ConstantMonad(Err),
|
||||||
PointedFunctor(Err),
|
|
||||||
{
|
{
|
||||||
isOk: false,
|
isOk: false,
|
||||||
isErr: true,
|
isErr: true,
|
||||||
|
@ -102,8 +99,7 @@ export const Err = value => create(
|
||||||
export const Some = value => create(
|
export const Some = value => create(
|
||||||
Value(value),
|
Value(value),
|
||||||
Functor,
|
Functor,
|
||||||
PointedFunctor(Some),
|
Monad(Some),
|
||||||
Monad,
|
|
||||||
{
|
{
|
||||||
isSome: true,
|
isSome: true,
|
||||||
isNone: false,
|
isNone: false,
|
||||||
|
@ -115,8 +111,7 @@ export const None = () => NoneConstant
|
||||||
|
|
||||||
const NoneConstant = create(
|
const NoneConstant = create(
|
||||||
ConstantFunctor,
|
ConstantFunctor,
|
||||||
ConstantMonad,
|
ConstantMonad(None),
|
||||||
PointedFunctor(None),
|
|
||||||
{
|
{
|
||||||
isSome: false,
|
isSome: false,
|
||||||
isNone: true,
|
isNone: true,
|
||||||
|
|
Loading…
Add table
Reference in a new issue