monocle-ts
Advanced tools
Comparing version 1.0.0 to 1.1.0
111
CHANGELOG.md
@@ -5,9 +5,9 @@ # Changelog | ||
> | ||
> * [New Feature] | ||
> * [Bug Fix] | ||
> * [Breaking Change] | ||
> * [Documentation] | ||
> * [Internal] | ||
> * [Polish] | ||
> * [Experimental] | ||
> - [New Feature] | ||
> - [Bug Fix] | ||
> - [Breaking Change] | ||
> - [Documentation] | ||
> - [Internal] | ||
> - [Polish] | ||
> - [Experimental] | ||
@@ -17,89 +17,94 @@ **Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a | ||
# 1.1.0 | ||
- **New Feature** | ||
- add `Lens.fromProps` (@gcanti) | ||
# 1.0.0 | ||
* **Breaking Change** | ||
* upgrade to `fp-ts@1.0.0` (@gcanti) | ||
- **Breaking Change** | ||
- upgrade to `fp-ts@1.0.0` (@gcanti) | ||
# 0.5.2 | ||
* **New Feature** | ||
* add `Iso.reverse`, closes #36 (@gcanti) | ||
- **New Feature** | ||
- add `Iso.reverse`, closes #36 (@gcanti) | ||
# 0.5.1 | ||
* **Experimental** | ||
* add Flowtype support (@gcanti) | ||
- **Experimental** | ||
- add Flowtype support (@gcanti) | ||
# 0.5.0 | ||
* **Breaking Change** | ||
* upgrade to fp-ts 0.6 (@gcanti) | ||
- **Breaking Change** | ||
- upgrade to fp-ts 0.6 (@gcanti) | ||
# 0.4.4 | ||
* **New Feature** | ||
* add `Lens.fromNullableProp` (@gcanti) | ||
- **New Feature** | ||
- add `Lens.fromNullableProp` (@gcanti) | ||
# 0.4.3 | ||
* **New Feature** | ||
* `Prism`: add `set` method (@gcanti) | ||
* `Optional`: add `fromNullableProps` static function (@gcanti) | ||
* **Bug fix** | ||
* `Prism`: change `asOptional`, `asTraversal` implementations, fix #29 (@gcanti) | ||
- **New Feature** | ||
- `Prism`: add `set` method (@gcanti) | ||
- `Optional`: add `fromNullableProps` static function (@gcanti) | ||
- **Bug fix** | ||
- `Prism`: change `asOptional`, `asTraversal` implementations, fix #29 (@gcanti) | ||
# 0.4.2 | ||
* **Polish** | ||
* fix Optional laws (@gcanti) | ||
* remove `Endomorphism` type alias (@gcanti) | ||
- **Polish** | ||
- fix Optional laws (@gcanti) | ||
- remove `Endomorphism` type alias (@gcanti) | ||
# 0.4.1 | ||
* **New Feature** | ||
* Add aliases to ISO, closes #24 (@gcanti) | ||
- **New Feature** | ||
- Add aliases to ISO, closes #24 (@gcanti) | ||
# 0.4.0 | ||
* **Breaking Change** | ||
* upgrade to fp-ts 0.5 (@gcanti) | ||
* currying of all APIs (@gcanti) | ||
- **Breaking Change** | ||
- upgrade to fp-ts 0.5 (@gcanti) | ||
- currying of all APIs (@gcanti) | ||
# 0.3.2 | ||
* **Polish** | ||
* upgrade to latest fp-ts (0.4.3) (@gcanti) | ||
- **Polish** | ||
- upgrade to latest fp-ts (0.4.3) (@gcanti) | ||
# 0.3.1 | ||
* **New Feature** | ||
* Added Setter (@LiamGoodacre) | ||
* Added Getter (@LiamGoodacre) | ||
* Added all possible conversions (e.g asGetter, asFold, etc) (@LiamGoodacre) | ||
* Added all possible compositions (@LiamGoodacre) | ||
* add _tag fields (allows for tagged unions) (@gcanti) | ||
* **Polish** | ||
* Fixed some typos (Options/Option -> Optional) (@LiamGoodacre) | ||
* Minor rearrangement so conversions and compositions are grouped (@LiamGoodacre) | ||
- **New Feature** | ||
- Added Setter (@LiamGoodacre) | ||
- Added Getter (@LiamGoodacre) | ||
- Added all possible conversions (e.g asGetter, asFold, etc) (@LiamGoodacre) | ||
- Added all possible compositions (@LiamGoodacre) | ||
- add \_tag fields (allows for tagged unions) (@gcanti) | ||
- **Polish** | ||
- Fixed some typos (Options/Option -> Optional) (@LiamGoodacre) | ||
- Minor rearrangement so conversions and compositions are grouped (@LiamGoodacre) | ||
# 0.3.0 | ||
* **Breaking Change** | ||
* upgrade to latest fp-ts (@gcanti) | ||
- **Breaking Change** | ||
- upgrade to latest fp-ts (@gcanti) | ||
# 0.2.0 | ||
* **New Feature** | ||
* add `Prism.some`, closes #10 (@gcanti) | ||
* add `composeX`, closes #11 (@gcanti) | ||
* **Breaking Change** | ||
* upgrade to latest `fp-ts` (`monocle-ts` APIs are not changed though) (@gcanti) | ||
* drop `lib-jsnext` folder | ||
* remove `Optional.fromProp`, closes #9 (@gcanti) | ||
- **New Feature** | ||
- add `Prism.some`, closes #10 (@gcanti) | ||
- add `composeX`, closes #11 (@gcanti) | ||
- **Breaking Change** | ||
- upgrade to latest `fp-ts` (`monocle-ts` APIs are not changed though) (@gcanti) | ||
- drop `lib-jsnext` folder | ||
- remove `Optional.fromProp`, closes #9 (@gcanti) | ||
# 0.1.1 | ||
* **New Feature** | ||
* add `Prism.fromPredicate` | ||
* fix `Optional.fromProp` | ||
- **New Feature** | ||
- add `Prism.fromPredicate` | ||
- fix `Optional.fromProp` | ||
@@ -106,0 +111,0 @@ # 0.1.0 |
@@ -71,2 +71,6 @@ import { HKT, URIS, URIS2, URIS3, Type, Type2, Type3 } from 'fp-ts/lib/HKT'; | ||
static fromProp<T, P extends keyof T>(prop: P): Lens<T, T[P]>; | ||
/** generate a lens from a type and an array of props */ | ||
static fromProps<S>(): <P extends keyof S>(props: Array<P>) => Lens<S, { | ||
[K in P]: S[K]; | ||
}>; | ||
/** generate a lens from a type and a prop whose type is nullable */ | ||
@@ -143,3 +147,3 @@ static fromNullableProp<S, A extends S[K], K extends keyof S>(k: K, defaultValue: A): Lens<S, A>; | ||
constructor(getOption: (s: S) => Option<A>, set: (a: A) => (s: S) => S); | ||
static fromNullableProp: <S, A extends S[K], K extends keyof S>(k: K) => Optional<S, A>; | ||
static fromNullableProp: <S_1, A_1 extends S_1[K], K extends keyof S_1>(k: K) => Optional<S_1, A_1>; | ||
modify(f: (a: A) => A): (s: S) => S; | ||
@@ -146,0 +150,0 @@ modifyOption(f: (a: A) => A): (s: S) => Option<S>; |
@@ -63,3 +63,3 @@ "use strict"; | ||
var _this = this; | ||
return new Fold(function (M) { return function (f) { return function (s) { return f(_this.get(s)); }; }; }); | ||
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; }); | ||
}; | ||
@@ -132,11 +132,25 @@ /** view an Iso as a Getter */ | ||
return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) { | ||
var _a; | ||
return Object.assign({}, s, (_a = {}, _a[prop] = a, _a)); | ||
var _a; | ||
}; }); | ||
}; | ||
/** generate a lens from a type and an array of props */ | ||
Lens.fromProps = function () { | ||
return function (props) { | ||
var len = props.length; | ||
return new Lens(function (s) { | ||
var r = {}; | ||
for (var i = 0; i < len; i++) { | ||
var k = props[i]; | ||
r[k] = s[k]; | ||
} | ||
return r; | ||
}, function (a) { return function (s) { return Object.assign({}, s, a); }; }); | ||
}; | ||
}; | ||
/** generate a lens from a type and a prop whose type is nullable */ | ||
Lens.fromNullableProp = function (k, defaultValue) { | ||
return new Lens(function (s) { return Option_1.fromNullable(s[k]).getOrElse(defaultValue); }, function (a) { return function (s) { | ||
var _a; | ||
return (__assign({}, s, (_a = {}, _a[k] = a, _a))); | ||
var _a; | ||
}; }); | ||
@@ -173,3 +187,3 @@ }; | ||
var _this = this; | ||
return new Fold(function (M) { return function (f) { return function (s) { return f(_this.get(s)); }; }; }); | ||
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; }); | ||
}; | ||
@@ -373,4 +387,4 @@ /** compose a Lens with a Lens */ | ||
return new Optional(function (s) { return Option_1.fromNullable(s[k]); }, function (a) { return function (s) { | ||
var _a; | ||
return (__assign({}, s, (_a = {}, _a[k] = a, _a))); | ||
var _a; | ||
}; }); | ||
@@ -454,3 +468,3 @@ }; | ||
var _this = this; | ||
return new Fold(function (M) { return function (f) { return function (s) { return f(_this.get(s)); }; }; }); | ||
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; }); | ||
}; | ||
@@ -457,0 +471,0 @@ /** compose a Getter with a Getter */ |
{ | ||
"name": "monocle-ts", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A porting of scala monocle library to TypeScript", | ||
"files": ["lib"], | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"scripts": { | ||
"lint": "tslint src/**/*.ts test/**/*.ts", | ||
"typings-checker": | ||
"typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts", | ||
"mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts", | ||
"prettier": | ||
"prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test,examples}/**/*.ts\"", | ||
"fix-prettier": | ||
"prettier --no-semi --single-quote --print-width 120 --parser typescript --write \"{src,test,examples}/**/*.ts\"", | ||
"test": "npm run prettier && npm run lint && npm run typings-checker && npm run mocha", | ||
"lint": "tslint -p tsconfig.json src/**/*.ts test/**/*.ts", | ||
"jest": "jest", | ||
"prettier": "prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test,examples}/**/*.ts\"", | ||
"fix-prettier": "prettier --no-semi --single-quote --print-width 120 --parser typescript --write \"{src,test,examples}/**/*.ts\"", | ||
"test": "npm run prettier && npm run lint && npm run dtslint && npm run jest", | ||
"clean": "rm -rf lib/*", | ||
"build": "npm run clean && tsc", | ||
"docs-fix-prettier": "prettier --no-semi --single-quote --print-width 120 --parser markdown --write \"README.md\"", | ||
"docs": "doctoc README.md && npm run docs-fix-prettier" | ||
"docs": "doctoc README.md && npm run docs-fix-prettier", | ||
"dtslint": "dtslint dtslint" | ||
}, | ||
@@ -37,15 +36,46 @@ "repository": { | ||
"devDependencies": { | ||
"@types/mocha": "2.2.38", | ||
"@types/jest": "^22.2.2", | ||
"@types/node": "7.0.4", | ||
"doctoc": "1.3.0", | ||
"mocha": "3.2.0", | ||
"prettier": "1.8.2", | ||
"ts-node": "3.1.0", | ||
"tslint": "4.4.2", | ||
"tslint-config-standard": "4.0.0", | ||
"typescript": "^2.7.1", | ||
"typings-checker": "1.1.2" | ||
"dtslint": "^0.3.0", | ||
"jest": "^22.4.3", | ||
"prettier": "^1.13.5", | ||
"ts-jest": "^22.4.2", | ||
"tslint": "5.9.1", | ||
"tslint-config-standard": "7.0.0", | ||
"typescript": "^2.9.1" | ||
}, | ||
"tags": ["typescript", "functional-programming", "optics", "lens", "fp-ts"], | ||
"keywords": ["typescript", "functional-programming", "optics", "lens", "fp-ts"] | ||
"tags": [ | ||
"typescript", | ||
"functional-programming", | ||
"optics", | ||
"lens", | ||
"fp-ts" | ||
], | ||
"keywords": [ | ||
"typescript", | ||
"functional-programming", | ||
"optics", | ||
"lens", | ||
"fp-ts" | ||
], | ||
"jest": { | ||
"globals": { | ||
"ts-jest": { | ||
"skipBabel": true | ||
} | ||
}, | ||
"collectCoverage": true, | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": "test", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"helpers.ts" | ||
] | ||
} | ||
} |
280
README.md
@@ -118,133 +118,132 @@ # Motivation | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
* [Iso](#iso) | ||
* [Methods](#methods) | ||
* [unwrap](#unwrap) | ||
* [to](#to) | ||
* [wrap](#wrap) | ||
* [from](#from) | ||
* [reverse](#reverse) | ||
* [modify](#modify) | ||
* [asLens](#aslens) | ||
* [asPrism](#asprism) | ||
* [asOptional](#asoptional) | ||
* [asTraversal](#astraversal) | ||
* [asFold](#asfold) | ||
* [asGetter](#asgetter) | ||
* [asSetter](#assetter) | ||
* [compose](#compose) | ||
* [composeLens](#composelens) | ||
* [composePrism](#composeprism) | ||
* [composeOptional](#composeoptional) | ||
* [composeTraversal](#composetraversal) | ||
* [composeFold](#composefold) | ||
* [composeGetter](#composegetter) | ||
* [composeSetter](#composesetter) | ||
* [Lens](#lens) | ||
* [fromPath](#frompath) | ||
* [fromProp](#fromprop) | ||
* [fromNullableProp](#fromnullableprop) | ||
* [Methods](#methods-1) | ||
* [modify](#modify-1) | ||
* [asOptional](#asoptional-1) | ||
* [asTraversal](#astraversal-1) | ||
* [asSetter](#assetter-1) | ||
* [asGetter](#asgetter-1) | ||
* [asFold](#asfold-1) | ||
* [compose](#compose-1) | ||
* [composeGetter](#composegetter-1) | ||
* [composeFold](#composefold-1) | ||
* [composeOptional](#composeoptional-1) | ||
* [composeTraversal](#composetraversal-1) | ||
* [composeSetter](#composesetter-1) | ||
* [composeIso](#composeiso) | ||
* [composePrism](#composeprism-1) | ||
* [Prism](#prism) | ||
* [fromPredicate](#frompredicate) | ||
* [some](#some) | ||
* [Methods](#methods-2) | ||
* [modify](#modify-2) | ||
* [modifyOption](#modifyoption) | ||
* [set](#set) | ||
* [asOptional](#asoptional-2) | ||
* [asTraversal](#astraversal-2) | ||
* [asSetter](#assetter-2) | ||
* [asFold](#asfold-2) | ||
* [compose](#compose-2) | ||
* [composeOptional](#composeoptional-2) | ||
* [composeTraversal](#composetraversal-2) | ||
* [composeFold](#composefold-2) | ||
* [composeSetter](#composesetter-2) | ||
* [composeIso](#composeiso-1) | ||
* [composeLens](#composelens-1) | ||
* [composeGetter](#composegetter-2) | ||
* [Optional](#optional) | ||
* [fromNullableProp](#fromnullableprop-1) | ||
* [Methods](#methods-3) | ||
* [modify](#modify-3) | ||
* [modifyOption](#modifyoption-1) | ||
* [asTraversal](#astraversal-3) | ||
* [asFold](#asfold-3) | ||
* [asSetter](#assetter-3) | ||
* [compose](#compose-3) | ||
* [composeTraversal](#composetraversal-3) | ||
* [composeFold](#composefold-3) | ||
* [composeSetter](#composesetter-3) | ||
* [composeLens](#composelens-2) | ||
* [composePrism](#composeprism-2) | ||
* [composeIso](#composeiso-2) | ||
* [composeGetter](#composegetter-3) | ||
* [Traversal](#traversal) | ||
* [Methods](#methods-4) | ||
* [modify](#modify-4) | ||
* [set](#set-1) | ||
* [asFold](#asfold-4) | ||
* [asSetter](#assetter-4) | ||
* [compose](#compose-4) | ||
* [composeFold](#composefold-4) | ||
* [composeSetter](#composesetter-4) | ||
* [composeOptional](#composeoptional-3) | ||
* [composeLens](#composelens-3) | ||
* [composePrism](#composeprism-3) | ||
* [composeIso](#composeiso-3) | ||
* [composeGetter](#composegetter-4) | ||
* [Getter](#getter) | ||
* [Methods](#methods-5) | ||
* [asFold](#asfold-5) | ||
* [compose](#compose-5) | ||
* [composeFold](#composefold-5) | ||
* [composeLens](#composelens-4) | ||
* [composeIso](#composeiso-4) | ||
* [composeTraversal](#composetraversal-4) | ||
* [composeOptional](#composeoptional-4) | ||
* [composePrism](#composeprism-4) | ||
* [Fold](#fold) | ||
* [Methods](#methods-6) | ||
* [compose](#compose-6) | ||
* [composeGetter](#composegetter-5) | ||
* [composeTraversal](#composetraversal-5) | ||
* [composeOptional](#composeoptional-5) | ||
* [composeLens](#composelens-5) | ||
* [composePrism](#composeprism-5) | ||
* [composeIso](#composeiso-5) | ||
* [find](#find) | ||
* [headOption](#headoption) | ||
* [getAll](#getall) | ||
* [exist](#exist) | ||
* [all](#all) | ||
* [Setter](#setter) | ||
* [Methods](#methods-7) | ||
* [set](#set-2) | ||
* [compose](#compose-7) | ||
* [composeTraversal](#composetraversal-6) | ||
* [composeOptional](#composeoptional-6) | ||
* [composeLens](#composelens-6) | ||
* [composePrism](#composeprism-6) | ||
* [composeIso](#composeiso-6) | ||
* [fromTraversable](#fromtraversable) | ||
* [fromFoldable](#fromfoldable) | ||
- [Iso](#iso) | ||
- [Methods](#methods) | ||
- [unwrap](#unwrap) | ||
- [to](#to) | ||
- [wrap](#wrap) | ||
- [from](#from) | ||
- [reverse](#reverse) | ||
- [modify](#modify) | ||
- [asLens](#aslens) | ||
- [asPrism](#asprism) | ||
- [asOptional](#asoptional) | ||
- [asTraversal](#astraversal) | ||
- [asFold](#asfold) | ||
- [asGetter](#asgetter) | ||
- [asSetter](#assetter) | ||
- [compose](#compose) | ||
- [composeLens](#composelens) | ||
- [composePrism](#composeprism) | ||
- [composeOptional](#composeoptional) | ||
- [composeTraversal](#composetraversal) | ||
- [composeFold](#composefold) | ||
- [composeGetter](#composegetter) | ||
- [composeSetter](#composesetter) | ||
- [Lens](#lens) | ||
- [fromPath](#frompath) | ||
- [fromProp](#fromprop) | ||
- [fromProps](#fromprops) | ||
- [fromNullableProp](#fromnullableprop) | ||
- [Methods](#methods-1) | ||
- [modify](#modify-1) | ||
- [asOptional](#asoptional-1) | ||
- [asTraversal](#astraversal-1) | ||
- [asSetter](#assetter-1) | ||
- [asGetter](#asgetter-1) | ||
- [asFold](#asfold-1) | ||
- [compose](#compose-1) | ||
- [composeGetter](#composegetter-1) | ||
- [composeFold](#composefold-1) | ||
- [composeOptional](#composeoptional-1) | ||
- [composeTraversal](#composetraversal-1) | ||
- [composeSetter](#composesetter-1) | ||
- [composeIso](#composeiso) | ||
- [composePrism](#composeprism-1) | ||
- [Prism](#prism) | ||
- [fromPredicate](#frompredicate) | ||
- [some](#some) | ||
- [Methods](#methods-2) | ||
- [modify](#modify-2) | ||
- [modifyOption](#modifyoption) | ||
- [set](#set) | ||
- [asOptional](#asoptional-2) | ||
- [asTraversal](#astraversal-2) | ||
- [asSetter](#assetter-2) | ||
- [asFold](#asfold-2) | ||
- [compose](#compose-2) | ||
- [composeOptional](#composeoptional-2) | ||
- [composeTraversal](#composetraversal-2) | ||
- [composeFold](#composefold-2) | ||
- [composeSetter](#composesetter-2) | ||
- [composeIso](#composeiso-1) | ||
- [composeLens](#composelens-1) | ||
- [composeGetter](#composegetter-2) | ||
- [Optional](#optional) | ||
- [fromNullableProp](#fromnullableprop-1) | ||
- [Methods](#methods-3) | ||
- [modify](#modify-3) | ||
- [modifyOption](#modifyoption-1) | ||
- [asTraversal](#astraversal-3) | ||
- [asFold](#asfold-3) | ||
- [asSetter](#assetter-3) | ||
- [compose](#compose-3) | ||
- [composeTraversal](#composetraversal-3) | ||
- [composeFold](#composefold-3) | ||
- [composeSetter](#composesetter-3) | ||
- [composeLens](#composelens-2) | ||
- [composePrism](#composeprism-2) | ||
- [composeIso](#composeiso-2) | ||
- [composeGetter](#composegetter-3) | ||
- [Traversal](#traversal) | ||
- [Methods](#methods-4) | ||
- [modify](#modify-4) | ||
- [set](#set-1) | ||
- [asFold](#asfold-4) | ||
- [asSetter](#assetter-4) | ||
- [compose](#compose-4) | ||
- [composeFold](#composefold-4) | ||
- [composeSetter](#composesetter-4) | ||
- [composeOptional](#composeoptional-3) | ||
- [composeLens](#composelens-3) | ||
- [composePrism](#composeprism-3) | ||
- [composeIso](#composeiso-3) | ||
- [composeGetter](#composegetter-4) | ||
- [Getter](#getter) | ||
- [Methods](#methods-5) | ||
- [asFold](#asfold-5) | ||
- [compose](#compose-5) | ||
- [composeFold](#composefold-5) | ||
- [composeLens](#composelens-4) | ||
- [composeIso](#composeiso-4) | ||
- [composeTraversal](#composetraversal-4) | ||
- [composeOptional](#composeoptional-4) | ||
- [composePrism](#composeprism-4) | ||
- [Fold](#fold) | ||
- [Methods](#methods-6) | ||
- [compose](#compose-6) | ||
- [composeGetter](#composegetter-5) | ||
- [composeTraversal](#composetraversal-5) | ||
- [composeOptional](#composeoptional-5) | ||
- [composeLens](#composelens-5) | ||
- [composePrism](#composeprism-5) | ||
- [composeIso](#composeiso-5) | ||
- [find](#find) | ||
- [headOption](#headoption) | ||
- [getAll](#getall) | ||
- [exist](#exist) | ||
- [all](#all) | ||
- [Setter](#setter) | ||
- [Methods](#methods-7) | ||
- [set](#set-2) | ||
- [compose](#compose-7) | ||
- [composeTraversal](#composetraversal-6) | ||
- [composeOptional](#composeoptional-6) | ||
- [composeLens](#composelens-6) | ||
- [composePrism](#composeprism-6) | ||
- [composeIso](#composeiso-6) | ||
- [fromTraversable](#fromtraversable) | ||
- [fromFoldable](#fromfoldable) | ||
@@ -487,2 +486,27 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
## fromProps | ||
```ts | ||
<S>(): <P extends keyof S>(props: Array<P>) => Lens<S, { [K in P]: S[K] }> | ||
``` | ||
generate a lens from a type and an array of props | ||
Example | ||
```ts | ||
interface Person { | ||
name: string | ||
age: number | ||
rememberMe: boolean | ||
} | ||
const lens = Lens.fromProps<Person>()(['name', 'age']) | ||
const person: Person = { name: 'Giulio', age: 44, rememberMe: true } | ||
console.log(lens.get(person)) // { name: 'Giulio', age: 44 } | ||
console.log(lens.set({ name: 'Guido', age: 47 })(person)) // { name: 'Guido', age: 47, rememberMe: true } | ||
``` | ||
## fromNullableProp | ||
@@ -489,0 +513,0 @@ |
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
86359
886
1343