Comparing version 0.0.744 to 0.0.745
import { AtomicPromise } from './promise'; | ||
import { curry } from './curry'; | ||
import { push } from './array'; | ||
@@ -40,4 +41,4 @@ export interface Either<a, b> { | ||
} | ||
public join<c>(this: Either<never, Either<never, c>>): Either<never, c> { | ||
return this.bind(m => m); | ||
public join<c>(this: Right<Either<never, c>>): Either<never, c> { | ||
return this.value; | ||
} | ||
@@ -131,9 +132,5 @@ public extract(): b; | ||
return Array.isArray(fm) | ||
? fm.reduce((acc, m) => | ||
acc.bind(as => | ||
m.fmap(a => | ||
[...as, a])) | ||
, Return([])) | ||
? fm.reduce((acc, m) => acc.bind(as => m.fmap(a => push(as, [a]))), Return([])) | ||
: fm.extract(b => AtomicPromise.resolve(new Left(b)), a => AtomicPromise.resolve(a).then<Either<a, b>>(Return)); | ||
} | ||
} |
17
maybe.ts
import { AtomicPromise } from './promise'; | ||
import { curry } from './curry'; | ||
import { push } from './array'; | ||
@@ -41,4 +42,4 @@ export interface Maybe<a> { | ||
} | ||
public join<b>(this: Maybe<Maybe<b>>): Maybe<b> { | ||
return this.bind(m => m); | ||
public join<b>(this: Just<Maybe<b>>): Maybe<b> { | ||
return this.value; | ||
} | ||
@@ -48,3 +49,3 @@ public guard(cond: boolean): Maybe<a> { | ||
? this | ||
: nothing; | ||
: Maybe.mzero; | ||
} | ||
@@ -135,10 +136,6 @@ public extract(): a; | ||
return Array.isArray(fm) | ||
? fm.reduce((acc, m) => | ||
acc.bind(as => | ||
m.fmap(a => | ||
[...as, a])) | ||
, Return([])) | ||
: fm.extract(() => AtomicPromise.resolve(Maybe.mzero), a => AtomicPromise.resolve(a).then(Return)); | ||
? fm.reduce((acc, m) => acc.bind(as => m.fmap(a => push(as, [a]))), Return([])) | ||
: fm.extract(() => AtomicPromise.resolve(mzero), a => AtomicPromise.resolve(a).then(Return)); | ||
} | ||
export const mzero: Maybe<never> = nothing; | ||
export const mzero = nothing; | ||
export function mplus<a>(ml: Maybe<a>, mr: Maybe<a>): Maybe<a> { | ||
@@ -145,0 +142,0 @@ return ml.extract(() => mr, () => ml); |
import { Monad } from './monad'; | ||
import { AtomicPromise } from '../promise'; | ||
import { noop } from '../function'; | ||
import { push } from '../array'; | ||
@@ -74,7 +75,3 @@ export class Either<a, b> extends Monad<b> { | ||
? fm.extract(b => AtomicPromise.resolve(new Left(b)), a => AtomicPromise.resolve(a).then<Either<a, b>>(Return)) | ||
: fm.reduce((acc, m) => | ||
acc.bind(as => | ||
m.fmap(a => | ||
[...as, a])) | ||
, Return([])); | ||
: fm.reduce((acc, m) => acc.bind(as => m.fmap(a => push(as, [a]))), Return([])); | ||
} | ||
@@ -92,3 +89,3 @@ } | ||
public override extract(): never; | ||
public override extract<c>(transform: (a: a) => c): c; | ||
public override extract<c>(left: (a: a) => c): c; | ||
public override extract<c>(left: (a: a) => c, right: (b: never) => c): c; | ||
@@ -112,3 +109,3 @@ public override extract<c>(left?: (a: a) => c): c { | ||
public override extract(): b; | ||
public override extract<c>(transform: (a: never) => c): b; | ||
public override extract<c>(left: (a: never) => c): b; | ||
public override extract<c>(left: (a: never) => c, right: (b: b) => c): c; | ||
@@ -115,0 +112,0 @@ public override extract<c>(left?: (a: never) => c, right?: (b: b) => c): b | c { |
import { MonadPlus } from './monadplus'; | ||
import { AtomicPromise } from '../promise'; | ||
import { noop } from '../function'; | ||
import { push } from '../array'; | ||
@@ -74,8 +75,4 @@ export class Maybe<a> extends MonadPlus<a> { | ||
return fm instanceof Maybe | ||
? fm.extract(() => AtomicPromise.resolve(Maybe.mzero), a => AtomicPromise.resolve(a).then(Return)) | ||
: fm.reduce((acc, m) => | ||
acc.bind(as => | ||
m.fmap(a => | ||
[...as, a])) | ||
, Return([])); | ||
? fm.extract(() => AtomicPromise.resolve(mzero), a => AtomicPromise.resolve(a).then(Return)) | ||
: fm.reduce((acc, m) => acc.bind(as => m.fmap(a => push(as, [a]))), Return([])); | ||
} | ||
@@ -122,3 +119,3 @@ } | ||
export namespace Maybe { | ||
export const mzero: Maybe<never> = new Nothing(); | ||
export const mzero = new Nothing(); | ||
export function mplus<a>(ml: Maybe<a>, mr: Maybe<a>): Maybe<a> { | ||
@@ -125,0 +122,0 @@ return new Maybe<a>(() => |
@@ -15,2 +15,2 @@ import * as Monad from './maybe.impl'; | ||
export type Nothing = Monad.Nothing; | ||
export const Nothing: Maybe<never> = Monad.Maybe.mzero; | ||
export const Nothing = Monad.Maybe.mzero; |
{ | ||
"name": "spica", | ||
"version": "0.0.744", | ||
"version": "0.0.745", | ||
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.", | ||
@@ -5,0 +5,0 @@ "private": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
620705
16899