monocle-ts
Advanced tools
Comparing version 2.3.6 to 2.3.7
@@ -16,2 +16,21 @@ # Changelog | ||
# 2.3.7 | ||
- **Experimental** | ||
- `At` | ||
- add `atReadonlyRecord` (@gcanti) | ||
- add `atReadonlyMap` (@gcanti) | ||
- add `atReadonlySet` (@gcanti) | ||
- deprecate `atRecord` (@gcanti) | ||
- `Ix` | ||
- add `indexReadonlyRecord` (@gcanti) | ||
- add `indexReadonlyArray` (@gcanti) | ||
- add `indexReadonlyMap` (@gcanti) | ||
- deprecate `indexRecord` (@gcanti) | ||
- deprecate `indexArray` (@gcanti) | ||
- `Optional` | ||
- add `composeLens` (@gcanti) | ||
- add `composePrism` (@gcanti) | ||
- add `setOption` (@gcanti) | ||
# 2.3.6 | ||
@@ -18,0 +37,0 @@ |
@@ -10,5 +10,7 @@ /** | ||
*/ | ||
import { Option } from 'fp-ts/es6/Option' | ||
import { Eq } from 'fp-ts/es6/Eq' | ||
import * as O from 'fp-ts/es6/Option' | ||
import { Iso } from './Iso' | ||
import { Lens } from './Lens' | ||
import Option = O.Option | ||
/** | ||
@@ -30,4 +32,22 @@ * @category model | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const atReadonlyRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const atReadonlyMap: <K>(E: Eq<K>) => <A = never>() => At<ReadonlyMap<K, A>, K, O.Option<A>> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const atReadonlySet: <A>(E: Eq<A>) => At<ReadonlySet<A>, A, boolean> | ||
/** | ||
* Use `atReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export declare const atRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>> |
@@ -0,2 +1,5 @@ | ||
import * as O from 'fp-ts/es6/Option'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import * as RM from 'fp-ts/es6/ReadonlyMap'; | ||
import * as RS from 'fp-ts/es6/ReadonlySet'; | ||
import * as _ from './internal'; | ||
@@ -17,4 +20,49 @@ // ------------------------------------------------------------------------------------- | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export var atReadonlyRecord = _.atReadonlyRecord; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export var atReadonlyMap = function (E) { return function () { | ||
var lookupE = RM.lookup(E); | ||
var deleteAtE = RM.deleteAt(E); | ||
var insertAtE = RM.insertAt(E); | ||
return { | ||
at: function (key) { return ({ | ||
get: lookupE(key), | ||
set: O.fold(function () { return deleteAtE(key); }, function (a) { return insertAtE(key, a); }) | ||
}); } | ||
}; | ||
}; }; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export var atReadonlySet = function (E) { | ||
var elemE = RS.elem(E); | ||
var insertE = RS.insert(E); | ||
var removeE = RS.remove(E); | ||
return { | ||
at: function (a) { | ||
var insert = insertE(a); | ||
var remove = removeE(a); | ||
return { | ||
get: elemE(a), | ||
set: function (b) { return function (s) { return (b ? insert(s) : remove(s)); }; } | ||
}; | ||
} | ||
}; | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// deprecated | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Use `atReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export var atRecord = _.atRecord; | ||
export var atRecord = _.atReadonlyRecord; |
@@ -46,4 +46,4 @@ import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/es6/Foldable' | ||
* Laws: | ||
* 1. reverseGet(get(s)) = s | ||
* 2. get(reversetGet(a)) = a | ||
* 1. `reverseGet(get(s)) = s` | ||
* 2. `get(reversetGet(a)) = a` | ||
* | ||
@@ -205,5 +205,5 @@ * @category constructor | ||
* Laws: | ||
* 1. get(set(a)(s)) = a | ||
* 2. set(get(s))(s) = s | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `get(set(a)(s)) = a` | ||
* 2. `set(get(s))(s) = s` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -411,4 +411,4 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, reverseGet)) = s | ||
* 2. getOption(reverseGet(a)) = some(a) | ||
* 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s` | ||
* 2. `getOption(reverseGet(a)) = some(a)` | ||
* | ||
@@ -564,5 +564,5 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, a => set(a)(s))) = s | ||
* 2. getOption(set(a)(s)) = pipe(getOption(s), map(_ => a)) | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s` | ||
* 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -569,0 +569,0 @@ * @category constructor |
@@ -67,4 +67,4 @@ /** | ||
* Laws: | ||
* 1. reverseGet(get(s)) = s | ||
* 2. get(reversetGet(a)) = a | ||
* 1. `reverseGet(get(s)) = s` | ||
* 2. `get(reversetGet(a)) = a` | ||
* | ||
@@ -248,5 +248,5 @@ * @category constructor | ||
* Laws: | ||
* 1. get(set(a)(s)) = a | ||
* 2. set(get(s))(s) = s | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `get(set(a)(s)) = a` | ||
* 2. `set(get(s))(s) = s` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -484,4 +484,4 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, reverseGet)) = s | ||
* 2. getOption(reverseGet(a)) = some(a) | ||
* 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s` | ||
* 2. `getOption(reverseGet(a)) = some(a)` | ||
* | ||
@@ -659,5 +659,5 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, a => set(a)(s))) = s | ||
* 2. getOption(set(a)(s)) = pipe(getOption(s), map(_ => a)) | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s` | ||
* 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -664,0 +664,0 @@ * @category constructor |
@@ -228,5 +228,5 @@ import * as A from 'fp-ts/es6/Array'; // TODO: replace with ReadonlyArray in v3 | ||
/** @internal */ | ||
export var indexArray = indexMutableArray; | ||
export var indexReadonlyArray = indexMutableArray; | ||
/** @internal */ | ||
export function indexRecord() { | ||
export function indexReadonlyRecord() { | ||
return { | ||
@@ -248,3 +248,3 @@ index: function (k) { return ({ | ||
/** @internal */ | ||
export function atRecord() { | ||
export function atReadonlyRecord() { | ||
return { | ||
@@ -251,0 +251,0 @@ at: function (key) { return ({ |
@@ -10,6 +10,8 @@ /** | ||
*/ | ||
import { Option } from 'fp-ts/es6/Option' | ||
import * as O from 'fp-ts/es6/Option' | ||
import { At } from './At' | ||
import { Iso } from './Iso' | ||
import { Optional } from './Optional' | ||
import { Eq } from 'fp-ts/es6/Eq' | ||
import Option = O.Option | ||
/** | ||
@@ -26,3 +28,3 @@ * @category model | ||
*/ | ||
export declare const fromAt: <T, J, B>(at: At<T, J, Option<B>>) => Index<T, J, B> | ||
export declare const fromAt: <T, J, B>(at: At<T, J, O.Option<B>>) => Index<T, J, B> | ||
/** | ||
@@ -37,9 +39,30 @@ * Lift an instance of `Index` using an `Iso` | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const indexReadonlyArray: <A = never>() => Index<ReadonlyArray<A>, number, A> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const indexReadonlyRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const indexReadonlyMap: <K>(E: Eq<K>) => <A = never>() => Index<ReadonlyMap<K, A>, K, A> | ||
/** | ||
* Use `indexReadonlyArray` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export declare const indexArray: <A = never>() => Index<ReadonlyArray<A>, number, A> | ||
/** | ||
* Use `indexReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export declare const indexRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A> |
@@ -0,3 +1,14 @@ | ||
/** | ||
* **This module is experimental** | ||
* | ||
* Experimental features are published in order to get early feedback from the community. | ||
* | ||
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice. | ||
* | ||
* @since 2.3.0 | ||
*/ | ||
import * as O from 'fp-ts/es6/Option'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import * as _ from './internal'; | ||
import * as RM from 'fp-ts/es6/ReadonlyMap'; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -24,9 +35,50 @@ // constructors | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export var indexReadonlyArray = _.indexReadonlyArray; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export var indexReadonlyRecord = _.indexReadonlyRecord; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export var indexReadonlyMap = function (E) { return function () { | ||
var lookupE = RM.lookup(E); | ||
var insertAtE = RM.insertAt(E); | ||
return { | ||
index: function (key) { | ||
var lookup = lookupE(key); | ||
return { | ||
getOption: lookup, | ||
set: function (next) { | ||
var insert = insertAtE(key, next); | ||
return function (s) { | ||
return pipe(lookup(s), O.fold(function () { return s; }, function (prev) { return (next === prev ? s : insert(s)); })); | ||
}; | ||
} | ||
}; | ||
} | ||
}; | ||
}; }; | ||
// ------------------------------------------------------------------------------------- | ||
// deprecated | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Use `indexReadonlyArray` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export var indexArray = _.indexArray; | ||
export var indexArray = _.indexReadonlyArray; | ||
/** | ||
* Use `indexReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export var indexRecord = _.indexRecord; | ||
export var indexRecord = _.indexReadonlyRecord; |
@@ -15,5 +15,5 @@ /** | ||
* | ||
* 1. get(set(a)(s)) = a | ||
* 2. set(get(s))(s) = s | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `get(set(a)(s)) = a` | ||
* 2. `set(get(s))(s) = s` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -20,0 +20,0 @@ * @since 2.3.0 |
@@ -110,3 +110,3 @@ import { flow } from 'fp-ts/es6/function'; | ||
export var index = function (i) { return function (sa) { | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexArray().index(i))); | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexReadonlyArray().index(i))); | ||
}; }; | ||
@@ -120,3 +120,3 @@ /** | ||
export var key = function (key) { return function (sa) { | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexRecord().index(key))); | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexReadonlyRecord().index(key))); | ||
}; }; | ||
@@ -130,3 +130,3 @@ /** | ||
export var atKey = function (key) { return function (sa) { | ||
return pipe(sa, compose(_.atRecord().at(key))); | ||
return pipe(sa, compose(_.atReadonlyRecord().at(key))); | ||
}; }; | ||
@@ -133,0 +133,0 @@ /** |
@@ -16,5 +16,5 @@ /** | ||
* | ||
* 1. pipe(getOption(s), fold(() => s, a => set(a)(s))) = s | ||
* 2. getOption(set(a)(s)) = pipe(getOption(s), map(_ => a)) | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s` | ||
* 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -31,2 +31,4 @@ * @since 2.3.0 | ||
import { Traversable1 } from 'fp-ts/es6/Traversable' | ||
import { Lens } from './Lens' | ||
import { Prism } from './Prism' | ||
import { Traversal } from './Traversal' | ||
@@ -48,3 +50,3 @@ import Option = O.Option | ||
/** | ||
* View a `Optional` as a `Traversal` | ||
* View a `Optional` as a `Traversal`. | ||
* | ||
@@ -56,3 +58,3 @@ * @category converters | ||
/** | ||
* Compose a `Optional` with a `Optional` | ||
* Compose a `Optional` with a `Optional`. | ||
* | ||
@@ -64,2 +66,16 @@ * @category compositions | ||
/** | ||
* Compose a `Optional` with a `Lens`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
export declare const composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B> | ||
/** | ||
* Compose a `Optional` with a `Prism`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
export declare const composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B> | ||
/** | ||
* @category combinators | ||
@@ -71,2 +87,7 @@ * @since 2.3.0 | ||
* @category combinators | ||
* @since 2.3.7 | ||
*/ | ||
export declare const setOption: <A>(a: A) => <S>(optional: Optional<S, A>) => (s: S) => O.Option<S> | ||
/** | ||
* @category combinators | ||
* @since 2.3.0 | ||
@@ -92,3 +113,3 @@ */ | ||
/** | ||
* Return an `Optional` from a `Optional` focused on a nullable value | ||
* Return an `Optional` from a `Optional` focused on a nullable value. | ||
* | ||
@@ -106,3 +127,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a prop | ||
* Return a `Optional` from a `Optional` and a prop. | ||
* | ||
@@ -114,3 +135,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a list of props | ||
* Return a `Optional` from a `Optional` and a list of props. | ||
* | ||
@@ -126,3 +147,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a component | ||
* Return a `Optional` from a `Optional` and a component. | ||
* | ||
@@ -136,3 +157,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray` | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray`. | ||
* | ||
@@ -144,3 +165,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key. | ||
* | ||
@@ -152,3 +173,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key. | ||
* | ||
@@ -162,3 +183,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type. | ||
* | ||
@@ -170,3 +191,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type. | ||
* | ||
@@ -178,3 +199,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type. | ||
* | ||
@@ -186,3 +207,3 @@ * @category combinators | ||
/** | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable` | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable`. | ||
* | ||
@@ -189,0 +210,0 @@ * @category combinators |
@@ -20,3 +20,3 @@ import { constant, flow } from 'fp-ts/es6/function'; | ||
/** | ||
* View a `Optional` as a `Traversal` | ||
* View a `Optional` as a `Traversal`. | ||
* | ||
@@ -31,3 +31,3 @@ * @category converters | ||
/** | ||
* Compose a `Optional` with a `Optional` | ||
* Compose a `Optional` with a `Optional`. | ||
* | ||
@@ -38,2 +38,20 @@ * @category compositions | ||
export var compose = _.optionalComposeOptional; | ||
/** | ||
* Compose a `Optional` with a `Lens`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
export var composeLens = function (ab) { return function (sa) { | ||
return _.optionalComposeOptional(_.lensAsOptional(ab))(sa); | ||
}; }; | ||
/** | ||
* Compose a `Optional` with a `Prism`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
export var composePrism = function (ab) { return function (sa) { | ||
return _.optionalComposeOptional(_.prismAsOptional(ab))(sa); | ||
}; }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -49,2 +67,7 @@ // combinators | ||
* @category combinators | ||
* @since 2.3.7 | ||
*/ | ||
export var setOption = function (a) { return modifyOption(function () { return a; }); }; | ||
/** | ||
* @category combinators | ||
* @since 2.3.0 | ||
@@ -59,3 +82,3 @@ */ | ||
/** | ||
* Return an `Optional` from a `Optional` focused on a nullable value | ||
* Return an `Optional` from a `Optional` focused on a nullable value. | ||
* | ||
@@ -72,3 +95,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a prop | ||
* Return a `Optional` from a `Optional` and a prop. | ||
* | ||
@@ -82,3 +105,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a list of props | ||
* Return a `Optional` from a `Optional` and a list of props. | ||
* | ||
@@ -96,3 +119,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a component | ||
* Return a `Optional` from a `Optional` and a component. | ||
* | ||
@@ -106,3 +129,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray` | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray`. | ||
* | ||
@@ -113,6 +136,6 @@ * @category combinators | ||
export var index = function (i) { return function (sa) { | ||
return pipe(sa, _.optionalComposeOptional(_.indexArray().index(i))); | ||
return pipe(sa, _.optionalComposeOptional(_.indexReadonlyArray().index(i))); | ||
}; }; | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key. | ||
* | ||
@@ -123,6 +146,6 @@ * @category combinators | ||
export var key = function (key) { return function (sa) { | ||
return pipe(sa, _.optionalComposeOptional(_.indexRecord().index(key))); | ||
return pipe(sa, _.optionalComposeOptional(_.indexReadonlyRecord().index(key))); | ||
}; }; | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key. | ||
* | ||
@@ -133,6 +156,6 @@ * @category combinators | ||
export var atKey = function (key) { return function (sa) { | ||
return pipe(sa, compose(_.lensAsOptional(_.atRecord().at(key)))); | ||
return pipe(sa, compose(_.lensAsOptional(_.atReadonlyRecord().at(key)))); | ||
}; }; | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type. | ||
* | ||
@@ -146,3 +169,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type. | ||
* | ||
@@ -156,3 +179,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type. | ||
* | ||
@@ -166,3 +189,3 @@ * @category combinators | ||
/** | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable` | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable`. | ||
* | ||
@@ -169,0 +192,0 @@ * @category combinators |
@@ -12,4 +12,4 @@ /** | ||
* | ||
* 1. pipe(getOption(s), fold(() => s, reverseGet)) = s | ||
* 2. getOption(reverseGet(a)) = some(a) | ||
* 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s` | ||
* 2. `getOption(reverseGet(a)) = some(a)` | ||
* | ||
@@ -16,0 +16,0 @@ * @since 2.3.0 |
@@ -138,3 +138,3 @@ import { flow, identity } from 'fp-ts/es6/function'; | ||
export var index = function (i) { return function (sa) { | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexArray().index(i))); | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexReadonlyArray().index(i))); | ||
}; }; | ||
@@ -148,3 +148,3 @@ /** | ||
export var key = function (key) { return function (sa) { | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexRecord().index(key))); | ||
return pipe(sa, asOptional, _.optionalComposeOptional(_.indexReadonlyRecord().index(key))); | ||
}; }; | ||
@@ -158,3 +158,3 @@ /** | ||
export var atKey = function (key) { return function (sa) { | ||
return _.prismComposeLens(_.atRecord().at(key))(sa); | ||
return _.prismComposeLens(_.atReadonlyRecord().at(key))(sa); | ||
}; }; | ||
@@ -161,0 +161,0 @@ /** |
@@ -92,3 +92,3 @@ import * as C from 'fp-ts/es6/Const'; | ||
export var index = function (i) { return function (sa) { | ||
return pipe(sa, compose(_.optionalAsTraversal(_.indexArray().index(i)))); | ||
return pipe(sa, compose(_.optionalAsTraversal(_.indexReadonlyArray().index(i)))); | ||
}; }; | ||
@@ -102,3 +102,3 @@ /** | ||
export var key = function (key) { return function (sa) { | ||
return pipe(sa, compose(_.optionalAsTraversal(_.indexRecord().index(key)))); | ||
return pipe(sa, compose(_.optionalAsTraversal(_.indexReadonlyRecord().index(key)))); | ||
}; }; | ||
@@ -112,3 +112,3 @@ /** | ||
export var atKey = function (key) { return function (sa) { | ||
return pipe(sa, compose(_.lensAsTraversal(_.atRecord().at(key)))); | ||
return pipe(sa, compose(_.lensAsTraversal(_.atReadonlyRecord().at(key)))); | ||
}; }; | ||
@@ -115,0 +115,0 @@ /** |
@@ -10,5 +10,7 @@ /** | ||
*/ | ||
import { Option } from 'fp-ts/lib/Option' | ||
import { Eq } from 'fp-ts/lib/Eq' | ||
import * as O from 'fp-ts/lib/Option' | ||
import { Iso } from './Iso' | ||
import { Lens } from './Lens' | ||
import Option = O.Option | ||
/** | ||
@@ -30,4 +32,22 @@ * @category model | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const atReadonlyRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const atReadonlyMap: <K>(E: Eq<K>) => <A = never>() => At<ReadonlyMap<K, A>, K, O.Option<A>> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const atReadonlySet: <A>(E: Eq<A>) => At<ReadonlySet<A>, A, boolean> | ||
/** | ||
* Use `atReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export declare const atRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>> |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.atRecord = exports.fromIso = void 0; | ||
exports.atRecord = exports.atReadonlySet = exports.atReadonlyMap = exports.atReadonlyRecord = exports.fromIso = void 0; | ||
var O = require("fp-ts/lib/Option"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var RM = require("fp-ts/lib/ReadonlyMap"); | ||
var RS = require("fp-ts/lib/ReadonlySet"); | ||
var _ = require("./internal"); | ||
@@ -21,4 +24,51 @@ // ------------------------------------------------------------------------------------- | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
exports.atReadonlyRecord = _.atReadonlyRecord; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
var atReadonlyMap = function (E) { return function () { | ||
var lookupE = RM.lookup(E); | ||
var deleteAtE = RM.deleteAt(E); | ||
var insertAtE = RM.insertAt(E); | ||
return { | ||
at: function (key) { return ({ | ||
get: lookupE(key), | ||
set: O.fold(function () { return deleteAtE(key); }, function (a) { return insertAtE(key, a); }) | ||
}); } | ||
}; | ||
}; }; | ||
exports.atReadonlyMap = atReadonlyMap; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
var atReadonlySet = function (E) { | ||
var elemE = RS.elem(E); | ||
var insertE = RS.insert(E); | ||
var removeE = RS.remove(E); | ||
return { | ||
at: function (a) { | ||
var insert = insertE(a); | ||
var remove = removeE(a); | ||
return { | ||
get: elemE(a), | ||
set: function (b) { return function (s) { return (b ? insert(s) : remove(s)); }; } | ||
}; | ||
} | ||
}; | ||
}; | ||
exports.atReadonlySet = atReadonlySet; | ||
// ------------------------------------------------------------------------------------- | ||
// deprecated | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Use `atReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
exports.atRecord = _.atRecord; | ||
exports.atRecord = _.atReadonlyRecord; |
@@ -46,4 +46,4 @@ import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/lib/Foldable' | ||
* Laws: | ||
* 1. reverseGet(get(s)) = s | ||
* 2. get(reversetGet(a)) = a | ||
* 1. `reverseGet(get(s)) = s` | ||
* 2. `get(reversetGet(a)) = a` | ||
* | ||
@@ -205,5 +205,5 @@ * @category constructor | ||
* Laws: | ||
* 1. get(set(a)(s)) = a | ||
* 2. set(get(s))(s) = s | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `get(set(a)(s)) = a` | ||
* 2. `set(get(s))(s) = s` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -411,4 +411,4 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, reverseGet)) = s | ||
* 2. getOption(reverseGet(a)) = some(a) | ||
* 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s` | ||
* 2. `getOption(reverseGet(a)) = some(a)` | ||
* | ||
@@ -564,5 +564,5 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, a => set(a)(s))) = s | ||
* 2. getOption(set(a)(s)) = pipe(getOption(s), map(_ => a)) | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s` | ||
* 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -569,0 +569,0 @@ * @category constructor |
@@ -48,4 +48,4 @@ "use strict"; | ||
* Laws: | ||
* 1. reverseGet(get(s)) = s | ||
* 2. get(reversetGet(a)) = a | ||
* 1. `reverseGet(get(s)) = s` | ||
* 2. `get(reversetGet(a)) = a` | ||
* | ||
@@ -229,5 +229,5 @@ * @category constructor | ||
* Laws: | ||
* 1. get(set(a)(s)) = a | ||
* 2. set(get(s))(s) = s | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `get(set(a)(s)) = a` | ||
* 2. `set(get(s))(s) = s` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -465,4 +465,4 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, reverseGet)) = s | ||
* 2. getOption(reverseGet(a)) = some(a) | ||
* 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s` | ||
* 2. `getOption(reverseGet(a)) = some(a)` | ||
* | ||
@@ -640,5 +640,5 @@ * @category constructor | ||
* Laws: | ||
* 1. pipe(getOption(s), fold(() => s, a => set(a)(s))) = s | ||
* 2. getOption(set(a)(s)) = pipe(getOption(s), map(_ => a)) | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s` | ||
* 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -645,0 +645,0 @@ * @category constructor |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.atRecord = exports.indexRecord = exports.indexArray = exports.fromTraversable = exports.traversalComposeTraversal = exports.findFirst = exports.optionalComposeOptional = exports.optionalModify = exports.optionalModifyOption = exports.optionalAsTraversal = exports.prismLeft = exports.prismRight = exports.prismSome = exports.prismFromPredicate = exports.prismFromNullable = exports.prismComposeLens = exports.prismSet = exports.prismModify = exports.prismModifyOption = exports.prismAsTraversal = exports.prismAsOptional = exports.lensComponent = exports.lensProps = exports.lensProp = exports.lensId = exports.lensComposePrism = exports.lensComposeLens = exports.lensAsTraversal = exports.lensAsOptional = exports.isoAsOptional = exports.isoAsLens = void 0; | ||
exports.atReadonlyRecord = exports.indexReadonlyRecord = exports.indexReadonlyArray = exports.fromTraversable = exports.traversalComposeTraversal = exports.findFirst = exports.optionalComposeOptional = exports.optionalModify = exports.optionalModifyOption = exports.optionalAsTraversal = exports.prismLeft = exports.prismRight = exports.prismSome = exports.prismFromPredicate = exports.prismFromNullable = exports.prismComposeLens = exports.prismSet = exports.prismModify = exports.prismModifyOption = exports.prismAsTraversal = exports.prismAsOptional = exports.lensComponent = exports.lensProps = exports.lensProp = exports.lensId = exports.lensComposePrism = exports.lensComposeLens = exports.lensAsTraversal = exports.lensAsOptional = exports.isoAsOptional = exports.isoAsLens = void 0; | ||
var A = require("fp-ts/lib/Array"); // TODO: replace with ReadonlyArray in v3 | ||
@@ -258,5 +258,5 @@ var R = require("fp-ts/lib/Record"); // TODO: replace with ReadonlyRecord in v3 | ||
/** @internal */ | ||
exports.indexArray = indexMutableArray; | ||
exports.indexReadonlyArray = indexMutableArray; | ||
/** @internal */ | ||
function indexRecord() { | ||
function indexReadonlyRecord() { | ||
return { | ||
@@ -274,3 +274,3 @@ index: function (k) { return ({ | ||
} | ||
exports.indexRecord = indexRecord; | ||
exports.indexReadonlyRecord = indexReadonlyRecord; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -280,3 +280,3 @@ // At | ||
/** @internal */ | ||
function atRecord() { | ||
function atReadonlyRecord() { | ||
return { | ||
@@ -289,2 +289,2 @@ at: function (key) { return ({ | ||
} | ||
exports.atRecord = atRecord; | ||
exports.atReadonlyRecord = atReadonlyRecord; |
@@ -10,6 +10,8 @@ /** | ||
*/ | ||
import { Option } from 'fp-ts/lib/Option' | ||
import * as O from 'fp-ts/lib/Option' | ||
import { At } from './At' | ||
import { Iso } from './Iso' | ||
import { Optional } from './Optional' | ||
import { Eq } from 'fp-ts/lib/Eq' | ||
import Option = O.Option | ||
/** | ||
@@ -26,3 +28,3 @@ * @category model | ||
*/ | ||
export declare const fromAt: <T, J, B>(at: At<T, J, Option<B>>) => Index<T, J, B> | ||
export declare const fromAt: <T, J, B>(at: At<T, J, O.Option<B>>) => Index<T, J, B> | ||
/** | ||
@@ -37,9 +39,30 @@ * Lift an instance of `Index` using an `Iso` | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const indexReadonlyArray: <A = never>() => Index<ReadonlyArray<A>, number, A> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const indexReadonlyRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A> | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
export declare const indexReadonlyMap: <K>(E: Eq<K>) => <A = never>() => Index<ReadonlyMap<K, A>, K, A> | ||
/** | ||
* Use `indexReadonlyArray` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export declare const indexArray: <A = never>() => Index<ReadonlyArray<A>, number, A> | ||
/** | ||
* Use `indexReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
export declare const indexRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A> |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.indexRecord = exports.indexArray = exports.fromIso = exports.fromAt = void 0; | ||
exports.indexRecord = exports.indexArray = exports.indexReadonlyMap = exports.indexReadonlyRecord = exports.indexReadonlyArray = exports.fromIso = exports.fromAt = void 0; | ||
/** | ||
* **This module is experimental** | ||
* | ||
* Experimental features are published in order to get early feedback from the community. | ||
* | ||
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice. | ||
* | ||
* @since 2.3.0 | ||
*/ | ||
var O = require("fp-ts/lib/Option"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var _ = require("./internal"); | ||
var RM = require("fp-ts/lib/ReadonlyMap"); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -29,9 +40,51 @@ // constructors | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
exports.indexReadonlyArray = _.indexReadonlyArray; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
exports.indexReadonlyRecord = _.indexReadonlyRecord; | ||
/** | ||
* @category constructors | ||
* @since 2.3.7 | ||
*/ | ||
var indexReadonlyMap = function (E) { return function () { | ||
var lookupE = RM.lookup(E); | ||
var insertAtE = RM.insertAt(E); | ||
return { | ||
index: function (key) { | ||
var lookup = lookupE(key); | ||
return { | ||
getOption: lookup, | ||
set: function (next) { | ||
var insert = insertAtE(key, next); | ||
return function (s) { | ||
return pipeable_1.pipe(lookup(s), O.fold(function () { return s; }, function (prev) { return (next === prev ? s : insert(s)); })); | ||
}; | ||
} | ||
}; | ||
} | ||
}; | ||
}; }; | ||
exports.indexReadonlyMap = indexReadonlyMap; | ||
// ------------------------------------------------------------------------------------- | ||
// deprecated | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Use `indexReadonlyArray` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
exports.indexArray = _.indexArray; | ||
exports.indexArray = _.indexReadonlyArray; | ||
/** | ||
* Use `indexReadonlyRecord` instead. | ||
* | ||
* @category constructors | ||
* @since 2.3.2 | ||
* @deprecated | ||
*/ | ||
exports.indexRecord = _.indexRecord; | ||
exports.indexRecord = _.indexReadonlyRecord; |
@@ -15,5 +15,5 @@ /** | ||
* | ||
* 1. get(set(a)(s)) = a | ||
* 2. set(get(s))(s) = s | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `get(set(a)(s)) = a` | ||
* 2. `set(get(s))(s) = s` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -20,0 +20,0 @@ * @since 2.3.0 |
@@ -118,3 +118,3 @@ "use strict"; | ||
var index = function (i) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexArray().index(i))); | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexReadonlyArray().index(i))); | ||
}; }; | ||
@@ -129,3 +129,3 @@ exports.index = index; | ||
var key = function (key) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexRecord().index(key))); | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexReadonlyRecord().index(key))); | ||
}; }; | ||
@@ -140,3 +140,3 @@ exports.key = key; | ||
var atKey = function (key) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.compose(_.atRecord().at(key))); | ||
return pipeable_1.pipe(sa, exports.compose(_.atReadonlyRecord().at(key))); | ||
}; }; | ||
@@ -143,0 +143,0 @@ exports.atKey = atKey; |
@@ -16,5 +16,5 @@ /** | ||
* | ||
* 1. pipe(getOption(s), fold(() => s, a => set(a)(s))) = s | ||
* 2. getOption(set(a)(s)) = pipe(getOption(s), map(_ => a)) | ||
* 3. set(a)(set(a)(s)) = set(a)(s) | ||
* 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s` | ||
* 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))` | ||
* 3. `set(a)(set(a)(s)) = set(a)(s)` | ||
* | ||
@@ -31,2 +31,4 @@ * @since 2.3.0 | ||
import { Traversable1 } from 'fp-ts/lib/Traversable' | ||
import { Lens } from './Lens' | ||
import { Prism } from './Prism' | ||
import { Traversal } from './Traversal' | ||
@@ -48,3 +50,3 @@ import Option = O.Option | ||
/** | ||
* View a `Optional` as a `Traversal` | ||
* View a `Optional` as a `Traversal`. | ||
* | ||
@@ -56,3 +58,3 @@ * @category converters | ||
/** | ||
* Compose a `Optional` with a `Optional` | ||
* Compose a `Optional` with a `Optional`. | ||
* | ||
@@ -64,2 +66,16 @@ * @category compositions | ||
/** | ||
* Compose a `Optional` with a `Lens`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
export declare const composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B> | ||
/** | ||
* Compose a `Optional` with a `Prism`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
export declare const composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B> | ||
/** | ||
* @category combinators | ||
@@ -71,2 +87,7 @@ * @since 2.3.0 | ||
* @category combinators | ||
* @since 2.3.7 | ||
*/ | ||
export declare const setOption: <A>(a: A) => <S>(optional: Optional<S, A>) => (s: S) => O.Option<S> | ||
/** | ||
* @category combinators | ||
* @since 2.3.0 | ||
@@ -92,3 +113,3 @@ */ | ||
/** | ||
* Return an `Optional` from a `Optional` focused on a nullable value | ||
* Return an `Optional` from a `Optional` focused on a nullable value. | ||
* | ||
@@ -106,3 +127,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a prop | ||
* Return a `Optional` from a `Optional` and a prop. | ||
* | ||
@@ -114,3 +135,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a list of props | ||
* Return a `Optional` from a `Optional` and a list of props. | ||
* | ||
@@ -126,3 +147,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a component | ||
* Return a `Optional` from a `Optional` and a component. | ||
* | ||
@@ -136,3 +157,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray` | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray`. | ||
* | ||
@@ -144,3 +165,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key. | ||
* | ||
@@ -152,3 +173,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key. | ||
* | ||
@@ -162,3 +183,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type. | ||
* | ||
@@ -170,3 +191,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type. | ||
* | ||
@@ -178,3 +199,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type. | ||
* | ||
@@ -186,3 +207,3 @@ * @category combinators | ||
/** | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable` | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable`. | ||
* | ||
@@ -189,0 +210,0 @@ * @category combinators |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.categoryOptional = exports.invariantOptional = exports.URI = exports.imap = exports.findFirst = exports.traverse = exports.left = exports.right = exports.some = exports.atKey = exports.key = exports.index = exports.component = exports.props = exports.prop = exports.filter = exports.fromNullable = exports.modifyF = exports.modify = exports.modifyOption = exports.compose = exports.asTraversal = exports.id = void 0; | ||
exports.categoryOptional = exports.invariantOptional = exports.URI = exports.imap = exports.findFirst = exports.traverse = exports.left = exports.right = exports.some = exports.atKey = exports.key = exports.index = exports.component = exports.props = exports.prop = exports.filter = exports.fromNullable = exports.modifyF = exports.modify = exports.setOption = exports.modifyOption = exports.composePrism = exports.composeLens = exports.compose = exports.asTraversal = exports.id = void 0; | ||
var function_1 = require("fp-ts/lib/function"); | ||
@@ -24,3 +24,3 @@ var O = require("fp-ts/lib/Option"); | ||
/** | ||
* View a `Optional` as a `Traversal` | ||
* View a `Optional` as a `Traversal`. | ||
* | ||
@@ -35,3 +35,3 @@ * @category converters | ||
/** | ||
* Compose a `Optional` with a `Optional` | ||
* Compose a `Optional` with a `Optional`. | ||
* | ||
@@ -42,2 +42,22 @@ * @category compositions | ||
exports.compose = _.optionalComposeOptional; | ||
/** | ||
* Compose a `Optional` with a `Lens`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
var composeLens = function (ab) { return function (sa) { | ||
return _.optionalComposeOptional(_.lensAsOptional(ab))(sa); | ||
}; }; | ||
exports.composeLens = composeLens; | ||
/** | ||
* Compose a `Optional` with a `Prism`. | ||
* | ||
* @category compositions | ||
* @since 2.3.7 | ||
*/ | ||
var composePrism = function (ab) { return function (sa) { | ||
return _.optionalComposeOptional(_.prismAsOptional(ab))(sa); | ||
}; }; | ||
exports.composePrism = composePrism; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -53,2 +73,8 @@ // combinators | ||
* @category combinators | ||
* @since 2.3.7 | ||
*/ | ||
var setOption = function (a) { return exports.modifyOption(function () { return a; }); }; | ||
exports.setOption = setOption; | ||
/** | ||
* @category combinators | ||
* @since 2.3.0 | ||
@@ -64,3 +90,3 @@ */ | ||
/** | ||
* Return an `Optional` from a `Optional` focused on a nullable value | ||
* Return an `Optional` from a `Optional` focused on a nullable value. | ||
* | ||
@@ -78,3 +104,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a prop | ||
* Return a `Optional` from a `Optional` and a prop. | ||
* | ||
@@ -89,3 +115,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a list of props | ||
* Return a `Optional` from a `Optional` and a list of props. | ||
* | ||
@@ -104,3 +130,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` and a component | ||
* Return a `Optional` from a `Optional` and a component. | ||
* | ||
@@ -115,3 +141,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray` | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyArray`. | ||
* | ||
@@ -122,7 +148,7 @@ * @category combinators | ||
var index = function (i) { return function (sa) { | ||
return pipeable_1.pipe(sa, _.optionalComposeOptional(_.indexArray().index(i))); | ||
return pipeable_1.pipe(sa, _.optionalComposeOptional(_.indexReadonlyArray().index(i))); | ||
}; }; | ||
exports.index = index; | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a key. | ||
* | ||
@@ -133,7 +159,7 @@ * @category combinators | ||
var key = function (key) { return function (sa) { | ||
return pipeable_1.pipe(sa, _.optionalComposeOptional(_.indexRecord().index(key))); | ||
return pipeable_1.pipe(sa, _.optionalComposeOptional(_.indexReadonlyRecord().index(key))); | ||
}; }; | ||
exports.key = key; | ||
/** | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key | ||
* Return a `Optional` from a `Optional` focused on a `ReadonlyRecord` and a required key. | ||
* | ||
@@ -144,7 +170,7 @@ * @category combinators | ||
var atKey = function (key) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.compose(_.lensAsOptional(_.atRecord().at(key)))); | ||
return pipeable_1.pipe(sa, exports.compose(_.lensAsOptional(_.atReadonlyRecord().at(key)))); | ||
}; }; | ||
exports.atKey = atKey; | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type | ||
* Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type. | ||
* | ||
@@ -158,3 +184,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type. | ||
* | ||
@@ -168,3 +194,3 @@ * @category combinators | ||
/** | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type | ||
* Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type. | ||
* | ||
@@ -178,3 +204,3 @@ * @category combinators | ||
/** | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable` | ||
* Return a `Traversal` from a `Optional` focused on a `Traversable`. | ||
* | ||
@@ -181,0 +207,0 @@ * @category combinators |
@@ -12,4 +12,4 @@ /** | ||
* | ||
* 1. pipe(getOption(s), fold(() => s, reverseGet)) = s | ||
* 2. getOption(reverseGet(a)) = some(a) | ||
* 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s` | ||
* 2. `getOption(reverseGet(a)) = some(a)` | ||
* | ||
@@ -16,0 +16,0 @@ * @since 2.3.0 |
@@ -149,3 +149,3 @@ "use strict"; | ||
var index = function (i) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexArray().index(i))); | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexReadonlyArray().index(i))); | ||
}; }; | ||
@@ -160,3 +160,3 @@ exports.index = index; | ||
var key = function (key) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexRecord().index(key))); | ||
return pipeable_1.pipe(sa, exports.asOptional, _.optionalComposeOptional(_.indexReadonlyRecord().index(key))); | ||
}; }; | ||
@@ -171,3 +171,3 @@ exports.key = key; | ||
var atKey = function (key) { return function (sa) { | ||
return _.prismComposeLens(_.atRecord().at(key))(sa); | ||
return _.prismComposeLens(_.atReadonlyRecord().at(key))(sa); | ||
}; }; | ||
@@ -174,0 +174,0 @@ exports.atKey = atKey; |
@@ -102,3 +102,3 @@ "use strict"; | ||
var index = function (i) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.compose(_.optionalAsTraversal(_.indexArray().index(i)))); | ||
return pipeable_1.pipe(sa, exports.compose(_.optionalAsTraversal(_.indexReadonlyArray().index(i)))); | ||
}; }; | ||
@@ -113,3 +113,3 @@ exports.index = index; | ||
var key = function (key) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.compose(_.optionalAsTraversal(_.indexRecord().index(key)))); | ||
return pipeable_1.pipe(sa, exports.compose(_.optionalAsTraversal(_.indexReadonlyRecord().index(key)))); | ||
}; }; | ||
@@ -124,3 +124,3 @@ exports.key = key; | ||
var atKey = function (key) { return function (sa) { | ||
return pipeable_1.pipe(sa, exports.compose(_.lensAsTraversal(_.atRecord().at(key)))); | ||
return pipeable_1.pipe(sa, exports.compose(_.lensAsTraversal(_.atReadonlyRecord().at(key)))); | ||
}; }; | ||
@@ -127,0 +127,0 @@ exports.atKey = atKey; |
{ | ||
"name": "monocle-ts", | ||
"version": "2.3.6", | ||
"version": "2.3.7", | ||
"description": "A porting of scala monocle library to TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
309886
10723