monocle-ts
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -47,2 +47,3 @@ import { HKT, HKTS } from 'fp-ts/lib/HKT'; | ||
constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S); | ||
static fromPredicate<A>(predicate: Predicate<A>): Prism<A, A>; | ||
modify(f: (a: A) => A, s: S): S; | ||
@@ -59,6 +60,6 @@ modifyOption(f: (a: A) => A, s: S): Option<S>; | ||
constructor(getOption: (s: S) => Option<A>, set: (a: A, s: S) => S); | ||
/** generate an optional from a type and a prop */ | ||
/** generate an optional from a type and a prop which is a `Option` */ | ||
static fromProp<T extends { | ||
[K in P]: Option<any>; | ||
}, P extends keyof T>(prop: P): Optional<T, T[P]>; | ||
}, P extends keyof T>(prop: P): Optional<T, T[P]['_A']>; | ||
modify(f: (a: A) => A, s: S): S; | ||
@@ -65,0 +66,0 @@ modifyOption(f: (a: A) => A, s: S): Option<S>; |
import { monoidArray, monoidAll, monoidAny } from 'fp-ts/lib/Monoid'; | ||
import { foldMap } from 'fp-ts/lib/Foldable'; | ||
import * as option from 'fp-ts/lib/Option'; | ||
import { Some } from 'fp-ts/lib/Option'; | ||
import { none, some } from 'fp-ts/lib/Option'; | ||
import { identity, constant } from 'fp-ts/lib/function'; | ||
@@ -33,3 +33,3 @@ import * as id from 'fp-ts/lib/Identity'; | ||
var _this = this; | ||
return new Prism(function (s) { return new Some(_this.get(s)); }, this.reverseGet); | ||
return new Prism(function (s) { return some(_this.get(s)); }, this.reverseGet); | ||
}; | ||
@@ -72,3 +72,3 @@ return Iso; | ||
var _this = this; | ||
return new Optional(function (s) { return new Some(_this.get(s)); }, this.set); | ||
return new Optional(function (s) { return some(_this.get(s)); }, this.set); | ||
}; | ||
@@ -89,2 +89,5 @@ return Lens; | ||
} | ||
Prism.fromPredicate = function (predicate) { | ||
return new Prism(function (s) { return predicate(s) ? some(s) : none; }, function (a) { return a; }); | ||
}; | ||
Prism.prototype.modify = function (f, s) { | ||
@@ -122,6 +125,6 @@ return this.modifyOption(f, s) | ||
} | ||
/** generate an optional from a type and a prop */ | ||
/** generate an optional from a type and a prop which is a `Option` */ | ||
Optional.fromProp = function (prop) { | ||
return new Optional(function (s) { return s[prop]; }, function (a, s) { | ||
return Object.assign({}, s, (_a = {}, _a[prop] = a, _a)); | ||
return Object.assign({}, s, (_a = {}, _a[prop] = some(a), _a)); | ||
var _a; | ||
@@ -128,0 +131,0 @@ }); |
@@ -47,2 +47,3 @@ import { HKT, HKTS } from 'fp-ts/lib/HKT'; | ||
constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S); | ||
static fromPredicate<A>(predicate: Predicate<A>): Prism<A, A>; | ||
modify(f: (a: A) => A, s: S): S; | ||
@@ -59,6 +60,6 @@ modifyOption(f: (a: A) => A, s: S): Option<S>; | ||
constructor(getOption: (s: S) => Option<A>, set: (a: A, s: S) => S); | ||
/** generate an optional from a type and a prop */ | ||
/** generate an optional from a type and a prop which is a `Option` */ | ||
static fromProp<T extends { | ||
[K in P]: Option<any>; | ||
}, P extends keyof T>(prop: P): Optional<T, T[P]>; | ||
}, P extends keyof T>(prop: P): Optional<T, T[P]['_A']>; | ||
modify(f: (a: A) => A, s: S): S; | ||
@@ -65,0 +66,0 @@ modifyOption(f: (a: A) => A, s: S): Option<S>; |
@@ -35,3 +35,3 @@ "use strict"; | ||
var _this = this; | ||
return new Prism(function (s) { return new Option_1.Some(_this.get(s)); }, this.reverseGet); | ||
return new Prism(function (s) { return Option_1.some(_this.get(s)); }, this.reverseGet); | ||
}; | ||
@@ -75,3 +75,3 @@ return Iso; | ||
var _this = this; | ||
return new Optional(function (s) { return new Option_1.Some(_this.get(s)); }, this.set); | ||
return new Optional(function (s) { return Option_1.some(_this.get(s)); }, this.set); | ||
}; | ||
@@ -92,2 +92,5 @@ return Lens; | ||
} | ||
Prism.fromPredicate = function (predicate) { | ||
return new Prism(function (s) { return predicate(s) ? Option_1.some(s) : Option_1.none; }, function (a) { return a; }); | ||
}; | ||
Prism.prototype.modify = function (f, s) { | ||
@@ -125,6 +128,6 @@ return this.modifyOption(f, s) | ||
} | ||
/** generate an optional from a type and a prop */ | ||
/** generate an optional from a type and a prop which is a `Option` */ | ||
Optional.fromProp = function (prop) { | ||
return new Optional(function (s) { return s[prop]; }, function (a, s) { | ||
return Object.assign({}, s, (_a = {}, _a[prop] = a, _a)); | ||
return Object.assign({}, s, (_a = {}, _a[prop] = Option_1.some(a), _a)); | ||
var _a; | ||
@@ -131,0 +134,0 @@ }); |
{ | ||
"name": "monocle-ts", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A porting of scala monocle library to TypeScript", | ||
@@ -13,3 +13,4 @@ "files": [ | ||
"scripts": { | ||
"test": "mocha -r ts-node/register test/*.ts", | ||
"mocha": "mocha -r ts-node/register test/*.ts", | ||
"test": "npm run mocha", | ||
"clean": "rm -rf lib/* && rm -rf lib-jsnext/*", | ||
@@ -29,3 +30,3 @@ "build": "npm run clean && tsc && tsc -m es6 --outDir lib-jsnext" | ||
"dependencies": { | ||
"fp-ts": "^0.2.0" | ||
"fp-ts": "^0.2.1" | ||
}, | ||
@@ -32,0 +33,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
51831
665
Updatedfp-ts@^0.2.1