Skip to content

Commit

Permalink
Internal: add ApplicativeIdentity to optimize tree shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed May 10, 2021
1 parent e1fea38 commit 24ed3e2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
high state of flux, you're at risk of it changing without notice.

# 2.3.10

# 2.3.9

Experimental modules require `fp-ts@^2.5.0`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monocle-ts",
"version": "2.3.9",
"version": "2.3.10",
"description": "A porting of scala monocle library to TypeScript",
"main": "lib/index.js",
"module": "es6/index.js",
Expand Down
10 changes: 3 additions & 7 deletions src/Traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import * as C from 'fp-ts/lib/Const'
import { Either } from 'fp-ts/lib/Either'
import { flow, identity, Predicate, Refinement } from 'fp-ts/lib/function'
import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT'
import * as I from 'fp-ts/lib/Identity'
import { Monoid } from 'fp-ts/lib/Monoid'
import { Option } from 'fp-ts/lib/Option'
import { pipe } from 'fp-ts/lib/pipeable'
Expand Down Expand Up @@ -156,17 +155,14 @@ export const composeOptional: <A, B>(ab: Optional<A, B>) => <S>(sa: Traversal<S,
* @category combinators
* @since 2.3.0
*/
export const modify = <A>(f: (a: A) => A) => <S>(sa: Traversal<S, A>): ((s: S) => S) => {
return sa.modifyF(I.identity)(f)
}
export const modify = <A>(f: (a: A) => A) => <S>(sa: Traversal<S, A>): ((s: S) => S) =>
sa.modifyF(_.ApplicativeIdentity)(f)

/**
* @category combinators
* @since 2.3.0
*/
export const set = <A>(a: A): (<S>(sa: Traversal<S, A>) => (s: S) => S) => {
return modify(() => a)
}
export const set = <A>(a: A): (<S>(sa: Traversal<S, A>) => (s: S) => S) => modify(() => a)

/**
* Return a `Traversal` from a `Traversal` focused on a nullable value.
Expand Down
13 changes: 12 additions & 1 deletion src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @since 2.3.0
*/
import { Applicative } from 'fp-ts/lib/Applicative'
import { Applicative, Applicative1 } from 'fp-ts/lib/Applicative'
import * as RA from 'fp-ts/lib/ReadonlyArray'
import * as RNEA from 'fp-ts/lib/ReadonlyNonEmptyArray'
import * as RR from 'fp-ts/lib/ReadonlyRecord'
Expand All @@ -25,6 +25,7 @@ import { Prism } from './Prism'
import { Traversal } from './Traversal'
import { At } from './At'
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'
import { URI as IURI } from 'fp-ts/lib/Identity'

// -------------------------------------------------------------------------------------
// Iso
Expand Down Expand Up @@ -321,6 +322,16 @@ export function traversalComposeTraversal<A, B>(ab: Traversal<A, B>): <S>(sa: Tr
return (sa) => traversal(<F>(F: Applicative<F>) => (f: (a: B) => HKT<F, B>) => sa.modifyF(F)(ab.modifyF(F)(f)))
}

/** @internal */
export const ApplicativeIdentity: Applicative1<IURI> = {
URI: 'Identity',
map: (fa, f) => f(fa),
of: identity,
ap:
/* istanbul ignore next */
(fab, fa) => fab(fa)
}

/** @internal */
export function fromTraversable<T extends URIS3>(T: Traversable3<T>): <R, E, A>() => Traversal<Kind3<T, R, E, A>, A>
/** @internal */
Expand Down

0 comments on commit 24ed3e2

Please sign in to comment.