Skip to content

Commit

Permalink
change structural tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jan 24, 2023
1 parent 776de1f commit da0bae8
Show file tree
Hide file tree
Showing 9 changed files with 573 additions and 527 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-parents-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fp-ts/core": patch
---

change structural tracking
7 changes: 2 additions & 5 deletions src/These.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { Either, Left, Right } from "@fp-ts/core/Either"
import type { LazyArg } from "@fp-ts/core/Function"
import { constNull, constUndefined, pipe } from "@fp-ts/core/Function"
import type { Kind, TypeLambda } from "@fp-ts/core/HKT"
import { structural } from "@fp-ts/core/internal/effect"
import { proto, structural } from "@fp-ts/core/internal/effect"
import * as either from "@fp-ts/core/internal/Either"
import * as option from "@fp-ts/core/internal/Option"
import type { Option } from "@fp-ts/core/Option"
Expand Down Expand Up @@ -109,10 +109,7 @@ export const of = right
* @since 1.0.0
*/
export const both = <E, A>(left: E, right: A): These<E, A> =>
Object.defineProperty({ _tag: "Both", left, right }, structural, {
enumerable: false,
value: true
})
Object.setPrototypeOf({ _tag: "Both", left, right }, proto)

/**
* @category constructors
Expand Down
6 changes: 3 additions & 3 deletions src/internal/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import type { Either, Left, Right } from "@fp-ts/core/Either"
import type { LazyArg } from "@fp-ts/core/Function"
import { structural } from "@fp-ts/core/internal/effect"
import { proto, structural } from "@fp-ts/core/internal/effect"
import * as option from "@fp-ts/core/internal/Option"
import type { Option } from "@fp-ts/core/Option"

Expand All @@ -21,11 +21,11 @@ export const isRight = <E, A>(ma: Either<E, A>): ma is Right<A> => ma._tag === "

/** @internal */
export const left = <E>(e: E): Either<E, never> =>
Object.defineProperty({ _tag: "Left", left: e }, structural, { enumerable: false, value: true })
Object.setPrototypeOf({ _tag: "Left", left: e }, proto)

/** @internal */
export const right = <A>(a: A): Either<never, A> =>
Object.defineProperty({ _tag: "Right", right: a }, structural, { enumerable: false, value: true })
Object.setPrototypeOf({ _tag: "Right", right: a }, proto)

/** @internal */
export const getLeft = <E, A>(
Expand Down
10 changes: 3 additions & 7 deletions src/internal/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @since 1.0.0
*/

import { structural } from "@fp-ts/core/internal/effect"
import { proto, structural } from "@fp-ts/core/internal/effect"
import type { None, Option, Some } from "@fp-ts/core/Option"

/** @internal */
Expand All @@ -17,14 +17,10 @@ export const isNone = <A>(fa: Option<A>): fa is None => fa._tag === "None"
export const isSome = <A>(fa: Option<A>): fa is Some<A> => fa._tag === "Some"

/** @internal */
export const none: Option<never> = Object.defineProperty({ _tag: "None" }, structural, {
enumerable: false,
value: true
})
export const none: Option<never> = Object.setPrototypeOf({ _tag: "None" }, proto)

/** @internal */
export const some = <A>(a: A): Option<A> =>
Object.defineProperty({ _tag: "Some", value: a }, structural, { enumerable: false, value: true })
export const some = <A>(a: A): Option<A> => Object.setPrototypeOf({ _tag: "Some", value: a }, proto)

/** @internal */
export const fromNullable = <A>(
Expand Down
3 changes: 3 additions & 0 deletions src/internal/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

/** @internal */
export const structural = Symbol.for("@effect/data/Equal/structural")

/** @internal */
export const proto = Object.setPrototypeOf({ [structural]: true }, Object.prototype)
Loading

0 comments on commit da0bae8

Please sign in to comment.