From e9bbb0ef41d34b0ea813deb70096cb99fc437152 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Thu, 1 Dec 2022 14:13:07 +0100 Subject: [PATCH] Remove `PrismDerivation.map/flatMap()` --- .../dataverse/src/derivations/IDerivation.ts | 27 -------------- .../dataverse/src/derivations/prism/prism.ts | 37 ------------------- 2 files changed, 64 deletions(-) diff --git a/packages/dataverse/src/derivations/IDerivation.ts b/packages/dataverse/src/derivations/IDerivation.ts index 3b37ac0..c5ddaf5 100644 --- a/packages/dataverse/src/derivations/IDerivation.ts +++ b/packages/dataverse/src/derivations/IDerivation.ts @@ -58,33 +58,6 @@ export interface IDerivation { * Gets the current value of the derivation. If the value is stale, it causes the derivation to freshen. */ 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(fn: (v: V) => T): IDerivation - - /** - * 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( - fn: (v: V) => R, - ): IDerivation ? T : R> } /** diff --git a/packages/dataverse/src/derivations/prism/prism.ts b/packages/dataverse/src/derivations/prism/prism.ts index 25649fa..ef9012d 100644 --- a/packages/dataverse/src/derivations/prism/prism.ts +++ b/packages/dataverse/src/derivations/prism/prism.ts @@ -360,43 +360,6 @@ class PrismDerivation implements IDerivation { reportResolutionEnd(this) 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(fn: (v: V) => T): IDerivation { - 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( - fn: (v: V) => R, - ): IDerivation ? T : R> { - console.log('flatMap') - return prism(() => { - return possibleDerivationToValue(fn(this.getValue())) - }) - } } interface PrismScope {