Remove PrismDerivation.map/flatMap()
This commit is contained in:
parent
a073984b2f
commit
e9bbb0ef41
2 changed files with 0 additions and 64 deletions
|
@ -58,33 +58,6 @@ export interface IDerivation<V> {
|
||||||
* Gets the current value of the derivation. If the value is stale, it causes the derivation to freshen.
|
* Gets the current value of the derivation. If the value is stale, it causes the derivation to freshen.
|
||||||
*/
|
*/
|
||||||
getValue(): V
|
getValue(): V
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new derivation from this derivation using the provided mapping function. The new derivation's value will be
|
|
||||||
* `fn(thisDerivation.getValue())`.
|
|
||||||
*
|
|
||||||
* @param fn - The mapping function to use. Note: it accepts a plain value, not a derivation.
|
|
||||||
*/
|
|
||||||
map<T>(fn: (v: V) => T): IDerivation<T>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as {@link IDerivation.map}, but the mapping function can also return a derivation, in which case the derivation returned
|
|
||||||
* by `flatMap` takes the value of that derivation.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // Simply using map() here would return the inner derivation when we call getValue()
|
|
||||||
* new Box(3).derivation.map((value) => new Box(value).derivation).getValue()
|
|
||||||
*
|
|
||||||
* // Using flatMap() eliminates the inner derivation
|
|
||||||
* new Box(3).derivation.flatMap((value) => new Box(value).derivation).getValue()
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @param fn - The mapping function to use. Note: it accepts a plain value, not a derivation.
|
|
||||||
*/
|
|
||||||
flatMap<R>(
|
|
||||||
fn: (v: V) => R,
|
|
||||||
): IDerivation<R extends IDerivation<infer T> ? T : R>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -360,43 +360,6 @@ class PrismDerivation<V> implements IDerivation<V> {
|
||||||
reportResolutionEnd(this)
|
reportResolutionEnd(this)
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple mapping function similar to Array.map()
|
|
||||||
*
|
|
||||||
* @deprecated This is a remnant of the old monadic api. Now it's functionally equal to `prism(() => fn(der.getValue()))`, so use that instead.
|
|
||||||
*/
|
|
||||||
map<T>(fn: (v: V) => T): IDerivation<T> {
|
|
||||||
console.log('map')
|
|
||||||
|
|
||||||
return prism(() => fn(this.getValue()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as {@link AbstractDerivation.map}, but the mapping function can also return a derivation, in which case the derivation returned
|
|
||||||
* by `flatMap` takes the value of that derivation.
|
|
||||||
*
|
|
||||||
* @deprecated This is a remnant of the old monadic api. Now it's functionally equal to `prism(() => val(fn(val(der))))`
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // Simply using map() here would return the inner derivation when we call getValue()
|
|
||||||
* new Box(3).derivation.map((value) => new Box(value).derivation).getValue()
|
|
||||||
*
|
|
||||||
* // Using flatMap() eliminates the inner derivation
|
|
||||||
* new Box(3).derivation.flatMap((value) => new Box(value).derivation).getValue()
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @param fn - The mapping function to use. Note: it accepts a plain value, not a derivation.
|
|
||||||
*/
|
|
||||||
flatMap<R>(
|
|
||||||
fn: (v: V) => R,
|
|
||||||
): IDerivation<R extends IDerivation<infer T> ? T : R> {
|
|
||||||
console.log('flatMap')
|
|
||||||
return prism(() => {
|
|
||||||
return possibleDerivationToValue(fn(this.getValue()))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PrismScope {
|
interface PrismScope {
|
||||||
|
|
Loading…
Reference in a new issue