Skip to content

Commit

Permalink
Refactored/added filter
Browse files Browse the repository at this point in the history
  • Loading branch information
chorobinaccess committed Jun 20, 2018
1 parent 669777e commit 19302b8
Show file tree
Hide file tree
Showing 21 changed files with 1,305 additions and 1,146 deletions.
2 changes: 2 additions & 0 deletions dist/fold/fold.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Monad, FoldMonad } from '../monad';
export declare const fold: <T, U>(f: (acc: U, val: T) => U, seed: U) => <TMonad extends Monad<T>>(monad: TMonad) => FoldMonad<TMonad, U>;
24 changes: 24 additions & 0 deletions dist/fold/fold.js
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var operators_1 = require("rxjs/operators");
var rxjs_1 = require("rxjs");
var maybe_1 = require("../maybe");
var immutable_1 = require("immutable");
exports.fold = function (f, seed) { return function (monad) {
var result;
if (rxjs_1.isObservable(monad)) {
result = operators_1.reduce(f, seed)(monad);
}
else if (maybe_1.isMaybe(monad)) {
result = maybe_1.foldLeft(f, seed)(monad);
}
else if (immutable_1.Iterable.isIterable(monad)) {
result = monad.reduce(f, seed);
}
else if (Array.isArray(monad)) {
result = monad.reduce(f, seed);
}
else {
throw new Error('Invalid type!');
}
return result;
}; };
1 change: 1 addition & 0 deletions dist/fold/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './fold';
6 changes: 6 additions & 0 deletions dist/fold/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./fold"));
3 changes: 2 additions & 1 deletion dist/maybe/maybe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Nothing } from './nothing';
export declare type Maybe<T> = Just<T> | Nothing;
export declare const isMaybe: <T>(couldBeMaybe: {}) => boolean;
export declare const isNothing: <T>(maybe: Maybe<T>) => boolean;
export declare const maybe: <T>(get: T) => Nothing;
export declare const maybe: <T>(get: T) => Maybe<T>;
export declare const fold: <T, U>(ifJust: (get: T) => U, ifNothing: U) => (maybe: Maybe<T>) => U;
export declare const foldLeft: <T, U>(ifJust: (acc: U, get: T) => U, ifNothing: U) => (maybe: Maybe<T>) => U;
export declare const map: <T, U>(f: (get: T) => U) => (maybe: Maybe<T>) => Nothing;
export declare const flatMap: <T, U>(f: (get: T) => Maybe<U>) => (maybe: Maybe<T>) => Nothing;
1 change: 1 addition & 0 deletions dist/maybe/maybe.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ exports.maybe = function (get) { return get ? { get: get, isNothing: false } : n
exports.fold = function (ifJust, ifNothing) { return function (maybe) {
return exports.isNothing(maybe) ? ifNothing : ifJust(maybe.get);
}; };
exports.foldLeft = function (ifJust, ifNothing) { return exports.fold(function (get) { return ifJust(ifNothing, get); }, ifNothing); };
exports.map = function (f) { return exports.fold(function (get) { return exports.maybe(f(get)); }, nothing_1.nothing); };
exports.flatMap = function (f) { return exports.fold(f, nothing_1.nothing); };
Loading

0 comments on commit 19302b8

Please sign in to comment.