flow-static-land
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -15,2 +15,9 @@ # Changelog | ||
## 0.2.5 | ||
- **New Feature** | ||
- add optics (Monocle partial porting) (@gcanti) | ||
- **Bug fix** | ||
- bad import references on in /lib build, fix #52 [@gcanti] | ||
## 0.2.4 | ||
@@ -17,0 +24,0 @@ |
@@ -350,4 +350,5 @@ 'use strict'; | ||
pempty: pempty, | ||
traverse: traverse | ||
traverse: traverse, | ||
unfoldr: unfoldr | ||
}); | ||
} |
@@ -19,2 +19,3 @@ 'use strict'; | ||
exports.bimap = bimap; | ||
exports.leftMap = leftMap; | ||
exports.ap = ap; | ||
@@ -36,2 +37,4 @@ exports.alt = alt; | ||
var _Identity = require('./Identity'); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
@@ -128,2 +131,6 @@ | ||
function leftMap(f, e) { | ||
return either.bimap(f, _Identity.id, e); | ||
} | ||
function ap(fab, fa) { | ||
@@ -130,0 +137,0 @@ var ab = prj(fab); |
@@ -10,2 +10,7 @@ 'use strict'; | ||
exports.headOption = headOption; | ||
exports.exist = exist; | ||
exports.all = all; | ||
exports.choice = choice; | ||
exports.composeFold = composeFold; | ||
exports.fromFoldable = fromFoldable; | ||
@@ -18,2 +23,16 @@ var _Monoid = require('./Monoid'); | ||
var maybe = _interopRequireWildcard(_Maybe); | ||
var _Either = require('./Either'); | ||
var either = _interopRequireWildcard(_Either); | ||
var _HKT = require('./HKT'); | ||
var _Foldable = require('./Foldable'); | ||
var foldable = _interopRequireWildcard(_Foldable); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
/** combine all targets using a target's Monoid */ | ||
@@ -36,4 +55,4 @@ function fold(fold, monoid, s) { | ||
function find(fold, p, s) { | ||
return fold.foldMap(_Maybe.first, function (a) { | ||
return p(a) ? (0, _Maybe.of)(a) : _Maybe.Nothing; | ||
return fold.foldMap(maybe.first, function (a) { | ||
return p(a) ? maybe.of(a) : maybe.Nothing; | ||
}, s); | ||
@@ -47,2 +66,43 @@ } | ||
}, s); | ||
} | ||
/** check if at least one target satisfies the predicate */ | ||
function exist(fold, p, s) { | ||
return fold.foldMap(_Monoid.any, p, s); | ||
} | ||
/** check if all targets satisfy the predicate */ | ||
function all(fold, p, s) { | ||
return fold.foldMap(_Monoid.all, p, s); | ||
} | ||
/** join two Fold with the same target */ | ||
function choice(fold1, fold2) { | ||
return { | ||
foldMap: function foldMap(monoid, f, s) { | ||
return either.either(function (s1) { | ||
return fold1.foldMap(monoid, f, s1); | ||
}, function (s2) { | ||
return fold2.foldMap(monoid, f, s2); | ||
}, s); | ||
} | ||
}; | ||
} | ||
function composeFold(ab, sa) { | ||
return { | ||
foldMap: function foldMap(monoid, f, s) { | ||
return sa.foldMap(monoid, function (a) { | ||
return ab.foldMap(monoid, f, a); | ||
}, s); | ||
} | ||
}; | ||
} | ||
function fromFoldable(fold) { | ||
return { | ||
foldMap: function foldMap(monoid, f, s) { | ||
return foldable.foldMap(fold, monoid, f, s); | ||
} | ||
}; | ||
} |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.Do = exports.first = exports.equals = exports.Nothing = exports.chain = exports.of = exports.map = exports.pempty = undefined; | ||
exports.Do = exports.toNothing = exports.first = exports.equals = exports.Nothing = exports.chain = exports.of = exports.map = exports.pempty = undefined; | ||
@@ -35,2 +35,4 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _Fun = require('./Fun'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -190,2 +192,4 @@ | ||
var toNothing = exports.toNothing = (0, _Fun.constant)(maybe.Nothing); | ||
/* | ||
@@ -192,0 +196,0 @@ |
@@ -9,2 +9,3 @@ 'use strict'; | ||
exports.getProductMonoid = getProductMonoid; | ||
exports.getDualMonoid = getDualMonoid; | ||
@@ -27,2 +28,11 @@ var _Semigroup = require('./Semigroup'); | ||
function getDualMonoid(monoid) { | ||
return { | ||
empty: monoid.empty, | ||
concat: function concat(x, y) { | ||
return monoid.concat(y, x); | ||
} | ||
}; | ||
} | ||
// Boolean monoid under conjunction | ||
@@ -29,0 +39,0 @@ var all = exports.all = { |
@@ -22,9 +22,9 @@ 'use strict'; | ||
var _HKT = require('../src/HKT'); | ||
var _HKT = require('./HKT'); | ||
var _Eff = require('../src/Eff'); | ||
var _Eff = require('./Eff'); | ||
var eff = _interopRequireWildcard(_Eff); | ||
var _Either = require('../src/Either'); | ||
var _Either = require('./Either'); | ||
@@ -31,0 +31,0 @@ var either = _interopRequireWildcard(_Either); |
{ | ||
"name": "flow-static-land", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Implementation of common algebraic types in JavaScript + Flow", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -15,2 +15,3 @@ // @flow | ||
import type { Tuple } from './Tuple' | ||
import type { Unfoldable } from './Unfoldable' | ||
@@ -280,3 +281,4 @@ import { HKT } from './HKT' | ||
pempty, | ||
traverse | ||
traverse, | ||
unfoldr | ||
}: | ||
@@ -290,3 +292,4 @@ Monoid<Arr<*>> & | ||
Alternative<IsArr> & | ||
Traversable<IsArr>) | ||
Traversable<IsArr> & | ||
Unfoldable<IsArr>) | ||
} |
@@ -16,2 +16,3 @@ // @flow | ||
import { Data1 } from './Data' | ||
import { id } from './Identity' | ||
@@ -86,2 +87,6 @@ class IsEither {} | ||
export function leftMap<L1, L2, R>(f: (l: L1) => L2, e: Either<L1, R>): Either<L2, R> { | ||
return either.bimap(f, id, e) | ||
} | ||
export function ap<L, A, B>(fab: Either<L, (a: A) => B>, fa: Either<L, A>): Either<L, B> { | ||
@@ -88,0 +93,0 @@ const ab = prj(fab) |
// @flow | ||
import type { Monoid } from './Monoid' | ||
import type { Maybe } from './Maybe' | ||
import type { Predicate } from './Fun' | ||
import type { Either } from './Either' | ||
import type { Foldable } from './Foldable' | ||
import { arrayMonoid } from './Monoid' | ||
import { arrayMonoid, all as allMonoid, any } from './Monoid' | ||
import { id } from './Identity' | ||
import { first, of, Nothing } from './Maybe' | ||
import * as maybe from './Maybe' | ||
import * as either from './Either' | ||
import { HKT } from './HKT' | ||
import * as foldable from './Foldable' | ||
@@ -30,4 +36,4 @@ export interface Fold<S, A> { | ||
/** find the first target of a [[Fold]] matching the predicate */ | ||
export function find<S, A>(fold: Fold<S, A>, p: (a: A) => boolean, s: S): Maybe<A> { | ||
return fold.foldMap(first, a => p(a) ? of(a) : Nothing, s) | ||
export function find<S, A>(fold: Fold<S, A>, p: Predicate<A>, s: S): Maybe<A> { | ||
return fold.foldMap(maybe.first, a => p(a) ? maybe.of(a) : maybe.Nothing, s) | ||
} | ||
@@ -39,1 +45,36 @@ | ||
} | ||
/** check if at least one target satisfies the predicate */ | ||
export function exist<S, A>(fold: Fold<S, A>, p: Predicate<A>, s: S): boolean { | ||
return fold.foldMap(any, p, s) | ||
} | ||
/** check if all targets satisfy the predicate */ | ||
export function all<S, A>(fold: Fold<S, A>, p: Predicate<A>, s: S): boolean { | ||
return fold.foldMap(allMonoid, p, s) | ||
} | ||
/** join two Fold with the same target */ | ||
export function choice<S1, S2, A>(fold1: Fold<S1, A>, fold2: Fold<S2, A>): Fold<Either<S1, S2>, A> { | ||
return { | ||
foldMap<M>(monoid: Monoid<M>, f: (a: A) => M, s: Either<S1, S2>): M { | ||
return either.either(s1 => fold1.foldMap(monoid, f, s1), s2 => fold2.foldMap(monoid, f, s2), s) | ||
} | ||
} | ||
} | ||
export function composeFold<S, A, B>(ab: Fold<A, B>, sa: Fold<S, A>): Fold<S, B> { | ||
return { | ||
foldMap<M>(monoid: Monoid<M>, f: (b: B) => M, s: S): M { | ||
return sa.foldMap(monoid, a => ab.foldMap(monoid, f, a), s) | ||
} | ||
} | ||
} | ||
export function fromFoldable<F, A>(fold: Foldable<F>): Fold<HKT<F, A>, A> { | ||
return { | ||
foldMap<M>(monoid: Monoid<M>, f: (a: A) => M, s: HKT<F, A>): M { | ||
return foldable.foldMap(fold, monoid, f, s) | ||
} | ||
} | ||
} |
@@ -17,2 +17,3 @@ // @flow | ||
import { id } from './Identity' | ||
import { constant } from './Fun' | ||
@@ -166,2 +167,4 @@ class IsMaybe {} | ||
export const toNothing = constant(maybe.Nothing) | ||
/* | ||
@@ -168,0 +171,0 @@ |
@@ -21,2 +21,9 @@ // @flow | ||
export function getDualMonoid<A>(monoid: Monoid<A>): Monoid<A> { | ||
return { | ||
empty: monoid.empty, | ||
concat: (x, y) => monoid.concat(y, x) | ||
} | ||
} | ||
// Boolean monoid under conjunction | ||
@@ -23,0 +30,0 @@ export const all: Monoid<boolean> = { |
// @flow | ||
import type { HKT2 } from '../src/HKT' | ||
import type { Monad } from '../src/Monad' | ||
import type { Eff } from '../src/Eff' | ||
import type { Either } from '../src/Either' | ||
import type { Monoid } from '../src/Monoid' | ||
import type { HKT2 } from './HKT' | ||
import type { Monad } from './Monad' | ||
import type { Eff } from './Eff' | ||
import type { Either } from './Either' | ||
import type { Monoid } from './Monoid' | ||
import { HKT } from '../src/HKT' | ||
import * as eff from '../src/Eff' | ||
import * as either from '../src/Either' | ||
import { HKT } from './HKT' | ||
import * as eff from './Eff' | ||
import * as either from './Either' | ||
@@ -12,0 +12,0 @@ class IsTask {} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
265557
190
5674