monocle-ts
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -15,2 +15,10 @@ # Changelog | ||
# 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) | ||
# 0.4.2 | ||
@@ -17,0 +25,0 @@ |
@@ -106,2 +106,4 @@ import { HKT, HKTS, HKTAs, HKT2S, HKT2As } from 'fp-ts/lib/HKT'; | ||
modifyOption(f: (a: A) => A): (s: S) => Option<S>; | ||
/** set the target of a Prism with a value */ | ||
set(a: A): (s: S) => S; | ||
/** view a Prism as a Optional */ | ||
@@ -137,2 +139,3 @@ asOptional(): Optional<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>; | ||
modify(f: (a: A) => A): (s: S) => S; | ||
@@ -139,0 +142,0 @@ modifyOption(f: (a: A) => A): (s: S) => Option<S>; |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,3 +23,3 @@ var Monoid_1 = require("fp-ts/lib/Monoid"); | ||
*/ | ||
var Iso = (function () { | ||
var Iso = /** @class */ (function () { | ||
function Iso(get, reverseGet) { | ||
@@ -31,3 +39,3 @@ this.get = get; | ||
var _this = this; | ||
return new Lens(this.get, function (a) { return function (s) { return _this.reverseGet(a); }; }); | ||
return new Lens(this.get, function (a) { return function (_) { return _this.reverseGet(a); }; }); | ||
}; | ||
@@ -42,3 +50,3 @@ /** view an Iso as a Prism */ | ||
var _this = this; | ||
return new Optional(function (s) { return Option_1.some(_this.get(s)); }, function (a) { return function (s) { return _this.reverseGet(a); }; }); | ||
return new Optional(function (s) { return Option_1.some(_this.get(s)); }, function (a) { return function (_) { return _this.reverseGet(a); }; }); | ||
}; | ||
@@ -114,3 +122,3 @@ /** view an Iso as a Traversal */ | ||
*/ | ||
var Lens = (function () { | ||
var Lens = /** @class */ (function () { | ||
function Lens(get, set) { | ||
@@ -201,3 +209,3 @@ this.get = get; | ||
*/ | ||
var Prism = (function () { | ||
var Prism = /** @class */ (function () { | ||
function Prism(getOption, reverseGet) { | ||
@@ -222,6 +230,10 @@ this.getOption = getOption; | ||
}; | ||
/** set the target of a Prism with a value */ | ||
Prism.prototype.set = function (a) { | ||
return this.modify(function () { return a; }); | ||
}; | ||
/** view a Prism as a Optional */ | ||
Prism.prototype.asOptional = function () { | ||
var _this = this; | ||
return new Optional(this.getOption, function (a) { return function (s) { return _this.reverseGet(a); }; }); | ||
return new Optional(this.getOption, function (a) { return _this.set(a); }); | ||
}; | ||
@@ -232,3 +244,3 @@ /** view a Prism as a Traversal */ | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
return _this.getOption(s).fold(function () { return F.of(s); }, function (a) { return F.map(function (fa) { return _this.reverseGet(a); }, f(a)); }); | ||
return _this.getOption(s).fold(function () { return F.of(s); }, function (a) { return F.map(function (a) { return _this.set(a)(s); }, f(a)); }); | ||
}; }; }); | ||
@@ -289,3 +301,3 @@ }; | ||
*/ | ||
var Optional = (function () { | ||
var Optional = /** @class */ (function () { | ||
function Optional(getOption, set) { | ||
@@ -354,6 +366,12 @@ this.getOption = getOption; | ||
}; | ||
Optional.fromNullableProp = function (k) { | ||
return new Optional(function (s) { return Option_1.fromNullable(s[k]); }, function (a) { return function (s) { | ||
return (__assign({}, s, (_a = {}, _a[k] = a, _a))); | ||
var _a; | ||
}; }); | ||
}; | ||
return Optional; | ||
}()); | ||
exports.Optional = Optional; | ||
var Traversal = (function () { | ||
var Traversal = /** @class */ (function () { | ||
function Traversal( | ||
@@ -423,3 +441,3 @@ // Van Laarhoven representation | ||
exports.Traversal = Traversal; | ||
var Getter = (function () { | ||
var Getter = /** @class */ (function () { | ||
function Getter(get) { | ||
@@ -466,3 +484,3 @@ this.get = get; | ||
exports.Getter = Getter; | ||
var Fold = (function () { | ||
var Fold = /** @class */ (function () { | ||
function Fold(foldMap) { | ||
@@ -516,3 +534,3 @@ this.foldMap = foldMap; | ||
exports.Fold = Fold; | ||
var Setter = (function () { | ||
var Setter = /** @class */ (function () { | ||
function Setter(modify) { | ||
@@ -554,3 +572,3 @@ this.modify = modify; | ||
exports.Setter = Setter; | ||
var Ops = (function () { | ||
var Ops = /** @class */ (function () { | ||
function Ops() { | ||
@@ -557,0 +575,0 @@ } |
{ | ||
"name": "monocle-ts", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "A porting of scala monocle library to TypeScript", | ||
@@ -10,9 +10,13 @@ "files": ["lib"], | ||
"lint": "tslint src/**/*.ts test/**/*.ts", | ||
"typings-checker": "typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts", | ||
"typings-checker": | ||
"typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts", | ||
"mocha": "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,exercises}/**/*.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", | ||
"clean": "rm -rf lib/*", | ||
"build": "npm run clean && tsc" | ||
"build": "npm run clean && tsc", | ||
"doctoc": "doctoc README.md" | ||
}, | ||
@@ -33,10 +37,11 @@ "repository": { | ||
"devDependencies": { | ||
"@types/mocha": "^2.2.38", | ||
"@types/node": "^7.0.4", | ||
"mocha": "^3.2.0", | ||
"prettier": "1.5.2", | ||
"@types/mocha": "2.2.38", | ||
"@types/node": "7.0.4", | ||
"doctoc": "1.3.0", | ||
"mocha": "3.2.0", | ||
"prettier": "1.7.0", | ||
"ts-node": "3.1.0", | ||
"tslint": "4.4.2", | ||
"tslint-config-standard": "4.0.0", | ||
"typescript": "2.4.1", | ||
"typescript": "2.5.2", | ||
"typings-checker": "1.1.2" | ||
@@ -43,0 +48,0 @@ }, |
1131
README.md
@@ -1,3 +0,1 @@ | ||
A (partial) porting of scala [monocle](https://github.com/julien-truffaut/Monocle) library to TypeScript | ||
# Motivation | ||
@@ -101,1 +99,1130 @@ | ||
All `Lenses` can be seen as `Optionals` where the optional element to zoom into is always present, hence composing an `Optional` and a `Lens` always produces an `Optional`. | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* | ||
- [Iso](#iso) | ||
- [Methods](#methods) | ||
- [unwrap](#unwrap) | ||
- [to](#to) | ||
- [wrap](#wrap) | ||
- [from](#from) | ||
- [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) | ||
- [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) | ||
- [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) | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
# Iso | ||
```ts | ||
class Iso<S, A> { | ||
constructor(readonly get: (s: S) => A, readonly reverseGet: (a: A) => S) | ||
} | ||
``` | ||
## Methods | ||
### unwrap | ||
```ts | ||
(s: S) => A | ||
``` | ||
Alias of `get` | ||
### to | ||
```ts | ||
(s: S) => A | ||
``` | ||
Alias of `get` | ||
### wrap | ||
```ts | ||
(a: A) => S | ||
``` | ||
Alias of `reverseGet` | ||
### from | ||
```ts | ||
(a: A) => S | ||
``` | ||
Alias of `reverseGet` | ||
### modify | ||
```ts | ||
(f: (a: A) => A): (s: S) => S | ||
``` | ||
### asLens | ||
```ts | ||
(): Lens<S, A> | ||
``` | ||
view an Iso as a Lens | ||
### asPrism | ||
```ts | ||
(): Prism<S, A> | ||
``` | ||
view an Iso as a Prism | ||
### asOptional | ||
```ts | ||
(): Optional<S, A> | ||
``` | ||
view an Iso as a Optional | ||
### asTraversal | ||
```ts | ||
(): Traversal<S, A> | ||
``` | ||
view an Iso as a Traversal | ||
### asFold | ||
```ts | ||
(): Fold<S, A> | ||
``` | ||
view an Iso as a Fold | ||
### asGetter | ||
```ts | ||
(): Getter<S, A> | ||
``` | ||
view an Iso as a Getter | ||
### asSetter | ||
```ts | ||
(): Setter<S, A> | ||
``` | ||
view an Iso as a Setter | ||
### compose | ||
```ts | ||
<B>(ab: Iso<A, B>): Iso<S, B> | ||
``` | ||
compose an Iso with an Iso | ||
### composeLens | ||
```ts | ||
<B>(ab: Lens<A, B>): Lens<S, B> | ||
``` | ||
compose an Iso with a Lens | ||
### composePrism | ||
```ts | ||
<B>(ab: Prism<A, B>): Prism<S, B> | ||
``` | ||
compose an Iso with a Prism | ||
### composeOptional | ||
```ts | ||
<B>(ab: Optional<A, B>): Optional<S, B> | ||
``` | ||
compose an Iso with an Optional | ||
### composeTraversal | ||
```ts | ||
<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
``` | ||
compose an Iso with a Traversal | ||
### composeFold | ||
```ts | ||
<B>(ab: Fold<A, B>): Fold<S, B> | ||
``` | ||
compose an Iso with a Fold | ||
### composeGetter | ||
```ts | ||
<B>(ab: Getter<A, B>): Getter<S, B> | ||
``` | ||
compose an Iso with a Getter | ||
### composeSetter | ||
```ts | ||
<B>(ab: Setter<A, B>): Setter<S, B> | ||
``` | ||
compose an Iso with a Setter | ||
# Lens | ||
```ts | ||
class Lens<S, A> { | ||
constructor(readonly get: (s: S) => A, readonly set: (a: A) => (s: S) => S) | ||
} | ||
``` | ||
## fromPath | ||
```ts | ||
// other 9 overloadings | ||
<T, K1 extends keyof T>(path: [K1]): Lens<T, T[K1]> | ||
``` | ||
Example | ||
```ts | ||
type Person = { | ||
name: string | ||
age: number | ||
address: { | ||
city: string | ||
} | ||
} | ||
const city = Lens.fromPath<Person, 'address', 'city'>(['address', 'city']) | ||
const person: Person = { name: 'Giulio', age: 43, address: { city: 'Milan' } } | ||
console.log(city.get(person)) // Milan | ||
console.log(city.set('London')(person)) // { name: 'Giulio', age: 43, address: { city: 'London' } } | ||
``` | ||
## fromProp | ||
```ts | ||
<T, P extends keyof T>(prop: P): Lens<T, T[P]> | ||
``` | ||
Example | ||
```ts | ||
type Person = { | ||
name: string | ||
age: number | ||
} | ||
const age = Lens.fromProp<Person, 'age'>('age') | ||
const person: Person = { name: 'Giulio', age: 43 } | ||
console.log(age.get(person)) // 43 | ||
console.log(age.set(44)(person)) // { name: 'Giulio', age: 44 } | ||
``` | ||
## Methods | ||
### modify | ||
```ts | ||
(f: (a: A) => A): (s: S) => S | ||
``` | ||
### asOptional | ||
```ts | ||
(): Optional<S, A> | ||
``` | ||
view a Lens as a Optional | ||
### asTraversal | ||
```ts | ||
(): Traversal<S, A> | ||
``` | ||
view a Lens as a Traversal | ||
### asSetter | ||
```ts | ||
(): Setter<S, A> | ||
``` | ||
view a Lens as a Setter | ||
### asGetter | ||
```ts | ||
(): Getter<S, A> | ||
``` | ||
view a Lens as a Getter | ||
### asFold | ||
```ts | ||
(): Fold<S, A> | ||
``` | ||
view a Lens as a Fold | ||
### compose | ||
```ts | ||
<B>(ab: Lens<A, B>): Lens<S, B> | ||
``` | ||
compose a Lens with a Lens | ||
### composeGetter | ||
```ts | ||
<B>(ab: Getter<A, B>): Getter<S, B> | ||
``` | ||
compose a Lens with a Getter | ||
### composeFold | ||
```ts | ||
<B>(ab: Fold<A, B>): Fold<S, B> | ||
``` | ||
compose a Lens with a Fold | ||
### composeOptional | ||
```ts | ||
<B>(ab: Optional<A, B>): Optional<S, B> | ||
``` | ||
compose a Lens with an Optional | ||
### composeTraversal | ||
```ts | ||
<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
``` | ||
compose a Lens with an Traversal | ||
### composeSetter | ||
```ts | ||
<B>(ab: Setter<A, B>): Setter<S, B> | ||
``` | ||
compose a Lens with an Setter | ||
### composeIso | ||
```ts | ||
<B>(ab: Iso<A, B>): Lens<S, B> | ||
``` | ||
compose a Lens with an Iso | ||
### composePrism | ||
```ts | ||
<B>(ab: Prism<A, B>): Optional<S, B> | ||
``` | ||
compose a Lens with a Prism | ||
# Prism | ||
```ts | ||
class Prism<S, A> { | ||
constructor(readonly getOption: (s: S) => Option<A>, readonly reverseGet: (a: A) => S) | ||
} | ||
``` | ||
## fromPredicate | ||
```ts | ||
<A>(predicate: Predicate<A>): Prism<A, A> | ||
``` | ||
## some | ||
```ts | ||
<A>(): Prism<Option<A>, A> | ||
``` | ||
## Methods | ||
### modify | ||
```ts | ||
(f: (a: A) => A): (s: S) => S | ||
``` | ||
### modifyOption | ||
```ts | ||
(f: (a: A) => A): (s: S) => Option<S> | ||
``` | ||
### set | ||
```ts | ||
(a: A): (s: S) => S | ||
``` | ||
set the target of a Prism with a value | ||
### asOptional | ||
```ts | ||
(): Optional<S, A> | ||
``` | ||
view a Prism as a Optional | ||
### asTraversal | ||
```ts | ||
(): Traversal<S, A> | ||
``` | ||
view a Prism as a Traversal | ||
### asSetter | ||
```ts | ||
(): Setter<S, A> | ||
``` | ||
view a Prism as a Setter | ||
### asFold | ||
```ts | ||
(): Fold<S, A> | ||
``` | ||
view a Prism as a Fold | ||
### compose | ||
```ts | ||
<B>(ab: Prism<A, B>): Prism<S, B> | ||
``` | ||
compose a Prism with a Prism | ||
### composeOptional | ||
```ts | ||
<B>(ab: Optional<A, B>): Optional<S, B> | ||
``` | ||
compose a Prism with a Optional | ||
### composeTraversal | ||
```ts | ||
<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
``` | ||
compose a Prism with a Traversal | ||
### composeFold | ||
```ts | ||
<B>(ab: Fold<A, B>): Fold<S, B> | ||
``` | ||
compose a Prism with a Fold | ||
### composeSetter | ||
```ts | ||
<B>(ab: Setter<A, B>): Setter<S, B> | ||
``` | ||
compose a Prism with a Setter | ||
### composeIso | ||
```ts | ||
<B>(ab: Iso<A, B>): Prism<S, B> | ||
``` | ||
compose a Prism with a Iso | ||
### composeLens | ||
```ts | ||
<B>(ab: Lens<A, B>): Optional<S, B> | ||
``` | ||
compose a Prism with a Lens | ||
### composeGetter | ||
```ts | ||
<B>(ab: Getter<A, B>): Fold<S, B> | ||
``` | ||
compose a Prism with a Getter | ||
# Optional | ||
```ts | ||
class Optional<S, A> { | ||
constructor(readonly getOption: (s: S) => Option<A>, readonly set: (a: A) => (s: S) => S) {} | ||
} | ||
``` | ||
## fromNullableProp | ||
```ts | ||
<S, A extends S[K], K extends keyof S>(k: K): Optional<S, A> | ||
``` | ||
Example | ||
```ts | ||
interface Phone { | ||
number: string | ||
} | ||
interface Employment { | ||
phone?: Phone | ||
} | ||
interface Info { | ||
employment?: Employment | ||
} | ||
interface Response { | ||
info?: Info | ||
} | ||
const info = Optional.fromNullableProp<Response, Info, 'info'>('info') | ||
const employment = Optional.fromNullableProp<Info, Employment, 'employment'>('employment') | ||
const phone = Optional.fromNullableProp<Employment, Phone, 'phone'>('phone') | ||
const number = Lens.fromProp<Phone, 'number'>('number') | ||
const numberFromResponse = info | ||
.compose(employment) | ||
.compose(phone) | ||
.composeLens(number) | ||
const response1: Response = { | ||
info: { | ||
employment: { | ||
phone: { | ||
number: '555-1234' | ||
} | ||
} | ||
} | ||
} | ||
const response2: Response = { | ||
info: { | ||
employment: {} | ||
} | ||
} | ||
numberFromResponse.getOption(response1) // some('555-1234') | ||
numberFromResponse.getOption(response2) // none | ||
``` | ||
## Methods | ||
### modify | ||
```ts | ||
(f: (a: A) => A): (s: S) => S | ||
``` | ||
### modifyOption | ||
```ts | ||
(f: (a: A) => A): (s: S) => Option<S> | ||
``` | ||
### asTraversal | ||
```ts | ||
(): Traversal<S, A> | ||
``` | ||
view a Optional as a Traversal | ||
### asFold | ||
```ts | ||
(): Fold<S, A> | ||
``` | ||
view an Optional as a Fold | ||
### asSetter | ||
```ts | ||
(): Setter<S, A> | ||
``` | ||
view an Optional as a Setter | ||
### compose | ||
```ts | ||
<B>(ab: Optional<A, B>): Optional<S, B> | ||
``` | ||
compose a Optional with a Optional | ||
### composeTraversal | ||
```ts | ||
<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
``` | ||
compose an Optional with a Traversal | ||
### composeFold | ||
```ts | ||
<B>(ab: Fold<A, B>): Fold<S, B> | ||
``` | ||
compose an Optional with a Fold | ||
### composeSetter | ||
```ts | ||
<B>(ab: Setter<A, B>): Setter<S, B> | ||
``` | ||
compose an Optional with a Setter | ||
### composeLens | ||
```ts | ||
<B>(ab: Lens<A, B>): Optional<S, B> | ||
``` | ||
compose an Optional with a Lens | ||
### composePrism | ||
```ts | ||
<B>(ab: Prism<A, B>): Optional<S, B> | ||
``` | ||
compose an Optional with a Prism | ||
### composeIso | ||
```ts | ||
<B>(ab: Iso<A, B>): Optional<S, B> | ||
``` | ||
compose an Optional with a Iso | ||
### composeGetter | ||
```ts | ||
<B>(ab: Getter<A, B>): Fold<S, B> | ||
``` | ||
compose an Optional with a Getter | ||
# Traversal | ||
```ts | ||
class Traversal<S, A> { | ||
constructor( | ||
readonly modifyF: <F>(F: Applicative<F>) => (f: (a: A) => HKT<F, A>) => (s: S) => HKT<F, S> | ||
) | ||
} | ||
``` | ||
## Methods | ||
### modify | ||
```ts | ||
(f: (a: A) => A): (s: S) => S | ||
``` | ||
### set | ||
```ts | ||
(a: A): (s: S) => S | ||
``` | ||
### asFold | ||
```ts | ||
(): Fold<S, A> | ||
``` | ||
view a Traversal as a Fold | ||
### asSetter | ||
```ts | ||
(): Setter<S, A> | ||
``` | ||
view a Traversal as a Setter | ||
### compose | ||
```ts | ||
<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
``` | ||
compose a Traversal with a Traversal | ||
### composeFold | ||
```ts | ||
<B>(ab: Fold<A, B>): Fold<S, B> | ||
``` | ||
compose a Traversal with a Fold | ||
### composeSetter | ||
```ts | ||
<B>(ab: Setter<A, B>): Setter<S, B> | ||
``` | ||
compose a Traversal with a Setter | ||
### composeOptional | ||
```ts | ||
<B>(ab: Optional<A, B>): Traversal<S, B> | ||
``` | ||
compose a Traversal with a Optional | ||
### composeLens | ||
```ts | ||
<B>(ab: Lens<A, B>): Traversal<S, B> | ||
``` | ||
compose a Traversal with a Lens | ||
### composePrism | ||
```ts | ||
<B>(ab: Prism<A, B>): Traversal<S, B> | ||
``` | ||
compose a Traversal with a Prism | ||
### composeIso | ||
```ts | ||
<B>(ab: Iso<A, B>): Traversal<S, B> | ||
``` | ||
compose a Traversal with a Iso | ||
### composeGetter | ||
```ts | ||
<B>(ab: Getter<A, B>): Fold<S, B> | ||
``` | ||
compose a Traversal with a Getter | ||
# Getter | ||
```ts | ||
class Getter<S, A> { | ||
constructor(readonly get: (s: S) => A) | ||
} | ||
``` | ||
## Methods | ||
### asFold | ||
```ts | ||
(): Fold<S, A> | ||
``` | ||
view a Getter as a Fold | ||
### compose | ||
```ts | ||
<B>(ab: Getter<A, B>): Getter<S, B> | ||
``` | ||
compose a Getter with a Getter | ||
### composeFold | ||
```ts | ||
<B>(ab: Fold<A, B>): Fold<S, B> | ||
``` | ||
compose a Getter with a Fold | ||
### composeLens | ||
```ts | ||
<B>(ab: Lens<A, B>): Getter<S, B> | ||
``` | ||
compose a Getter with a Lens | ||
### composeIso | ||
```ts | ||
<B>(ab: Iso<A, B>): Getter<S, B> | ||
``` | ||
compose a Getter with a Iso | ||
### composeTraversal | ||
```ts | ||
<B>(ab: Traversal<A, B>): Fold<S, B> | ||
``` | ||
compose a Getter with a Optional | ||
### composeOptional | ||
```ts | ||
<B>(ab: Optional<A, B>): Fold<S, B> | ||
``` | ||
compose a Getter with a Optional | ||
### composePrism | ||
```ts | ||
<B>(ab: Prism<A, B>): Fold<S, B> | ||
``` | ||
compose a Getter with a Prism | ||
# Fold | ||
```ts | ||
class Fold<S, A> { | ||
constructor(readonly foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M) | ||
} | ||
``` | ||
## Methods | ||
### compose | ||
```ts | ||
<B>(ab: Fold<A, B>): Fold<S, B> | ||
``` | ||
compose a Fold with a Fold | ||
### composeGetter | ||
```ts | ||
<B>(ab: Getter<A, B>): Fold<S, B> | ||
``` | ||
compose a Fold with a Getter | ||
### composeTraversal | ||
```ts | ||
<B>(ab: Traversal<A, B>): Fold<S, B> | ||
``` | ||
compose a Fold with a Traversal | ||
### composeOptional | ||
```ts | ||
<B>(ab: Optional<A, B>): Fold<S, B> | ||
``` | ||
compose a Fold with a Optional | ||
### composeLens | ||
```ts | ||
<B>(ab: Lens<A, B>): Fold<S, B> | ||
``` | ||
compose a Fold with a Lens | ||
### composePrism | ||
```ts | ||
<B>(ab: Prism<A, B>): Fold<S, B> | ||
``` | ||
compose a Fold with a Prism | ||
### composeIso | ||
```ts | ||
<B>(ab: Iso<A, B>): Fold<S, B> | ||
``` | ||
compose a Fold with a Iso | ||
### find | ||
```ts | ||
(p: Predicate<A>): (s: S) => Option<A> | ||
``` | ||
find the first target of a Fold matching the predicate | ||
### headOption | ||
```ts | ||
(s: S): Option<A> | ||
``` | ||
get the first target of a Fold | ||
### getAll | ||
```ts | ||
(s: S): Array<A> | ||
``` | ||
get all the targets of a Fold | ||
### exist | ||
```ts | ||
(p: Predicate<A>): Predicate<S> | ||
``` | ||
check if at least one target satisfies the predicate | ||
### all | ||
```ts | ||
(p: Predicate<A>): Predicate<S> | ||
``` | ||
check if all targets satisfy the predicate | ||
# Setter | ||
```ts | ||
class Setter<S, A> { | ||
constructor(readonly modify: (f: (a: A) => A) => (s: S) => S) | ||
} | ||
``` | ||
## Methods | ||
### set | ||
```ts | ||
(a: A): (s: S) => S | ||
``` | ||
### compose | ||
```ts | ||
<B>(ab: Setter<A, B>): Setter<S, B> | ||
``` | ||
compose a Setter with a Setter | ||
### composeTraversal | ||
```ts | ||
<B>(ab: Traversal<A, B>): Setter<S, B> | ||
``` | ||
compose a Setter with a Traversal | ||
### composeOptional | ||
```ts | ||
<B>(ab: Optional<A, B>): Setter<S, B> | ||
``` | ||
compose a Setter with a Optional | ||
### composeLens | ||
```ts | ||
<B>(ab: Lens<A, B>): Setter<S, B> | ||
``` | ||
compose a Setter with a Lens | ||
### composePrism | ||
```ts | ||
<B>(ab: Prism<A, B>): Setter<S, B> | ||
``` | ||
compose a Setter with a Prism | ||
### composeIso | ||
```ts | ||
<B>(ab: Iso<A, B>): Setter<S, B> | ||
``` | ||
compose a Setter with a Iso | ||
# fromTraversable | ||
```ts | ||
<T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A> | ||
``` | ||
create a Traversal from a Traversable | ||
# fromFoldable | ||
```ts | ||
<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A> | ||
``` | ||
create a Fold from a Foldable |
Sorry, the diff of this file is not supported yet
80901
853
1228
10