Skip to content

Commit

Permalink
Replace @fp-ts/core with @effect/data
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza authored and gcanti committed Feb 22, 2023
1 parent 69c2de5 commit d9a747d
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 102 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-yaks-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fp-ts/optic": minor
---

Switch to @effect/data from @fp-ts/core
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ flowchart TD
# Features

- **Unified Representation Of Optics**. All optics compose the same way because they are all instances of the same data type (`Optic`)
- **Integration**. Built-in optics for `@fp-ts/core` data structures, like `Option` and `Either`.
- **Integration**. Built-in optics for `@effect/data` data structures, like `Option` and `Either`.

## Introduction

`@fp-ts/optic` is a library that makes it easy to modify parts of larger data structures based on a single representation of an optic as a combination of a getter and setter.

`@fp-ts/optic` features a unified representation of optics, deep `@fp-ts/core` integration, helpful error messages.
`@fp-ts/optic` features a unified representation of optics, deep `@effect/data` integration, helpful error messages.

# Credits and sponsorship

Expand Down Expand Up @@ -85,7 +85,7 @@ import * as Optic from "@fp-ts/optic";
Let's say we have an employee and we need to upper case the first character of his company street name.

```ts
import * as O from "@fp-ts/core/Option";
import * as O from "@effect/data/Option";

interface Street {
readonly num: number;
Expand Down Expand Up @@ -138,7 +138,7 @@ Let's see what could we do with `@fp-ts/optic`
```ts
import * as Optic from "@fp-ts/optic";
import * as StringOptic from "@fp-ts/optic/data/String";
import * as String from "@fp-ts/core/String";
import * as String from "@effect/data/String";

const _firstChar: Optic.Optional<Employee, string> = Optic.id<Employee>()
.at("company")
Expand Down Expand Up @@ -318,7 +318,7 @@ const _a: Optic.Iso<Whole, Whole> = Optic.id<Whole>();
The `compose` method is a utility function that allows you to combine two or more optics into a single optic.

```ts
import { pipe } from "@fp-ts/core/Function";
import { pipe } from "@effect/data/Function";
import * as Optic from "@fp-ts/optic";

// This is the type of the data structure that the lens will be operating on.
Expand Down Expand Up @@ -356,7 +356,7 @@ const updated: Whole = pipe(whole, Optic.replace(_a)("bar")); // returns { a: "b
The `at` method is a utility function that creates an optic that focuses on a specific field within a data structure.

```ts
import { pipe } from "@fp-ts/core/Function";
import { pipe } from "@effect/data/Function";
import * as Optic from "@fp-ts/optic";

// This is the type of the data structure that the lens will be operating on.
Expand Down Expand Up @@ -394,7 +394,7 @@ const updated: Whole = pipe(whole, Optic.replace(_a)("bar")); // returns { a: "b
The `pick` method is a utility function that creates an optic that focuses on a group of keys within a data structure.

```ts
import { pipe } from "@fp-ts/core/Function";
import { pipe } from "@effect/data/Function";
import * as Optic from "@fp-ts/optic";

// This is the type of the data structure that the lens will be operating on.
Expand Down Expand Up @@ -435,7 +435,7 @@ const updated: Whole = pipe(whole, Optic.replace(_ab)({ a: "bar", b: 23 })); //
The `omit` method is a utility function that creates a lens that excludes a group of keys from a struct. This can be useful when you want to focus on a subset of a data structure and ignore certain fields.

```ts
import { pipe } from "@fp-ts/core/Function";
import { pipe } from "@effect/data/Function";
import * as Optic from "@fp-ts/optic";

interface Whole {
Expand Down Expand Up @@ -475,9 +475,9 @@ const updated: Whole = pipe(whole, Optic.replace(_ac)({ a: "bar", c: false }));
The `filter` method is a utility function that creates an optic that focuses on the elements of a data structure that match a specified predicate.

```ts
import { pipe } from "@fp-ts/core/Function";
import { pipe } from "@effect/data/Function";
import * as Optic from "@fp-ts/optic";
import type { Option } from "@fp-ts/core/Option";
import type { Option } from "@effect/data/Option";

// This is the type of the data structure that the prism will be operating on.
interface Whole {
Expand Down Expand Up @@ -514,9 +514,9 @@ const updated: Whole = pipe(whole, Optic.replace(_evenA)(4)); // returns { a: 4
The `nonNullable` method is a utility function that creates a `Prism` that focuses on the non-nullable values of a nullable type. This is useful when you want to manipulate or extract the value of a nullable type, but want to ignore the `null` values.

```ts
import { pipe } from "@fp-ts/core/Function";
import { pipe } from "@effect/data/Function";
import * as Optic from "@fp-ts/optic";
import type { Option } from "@fp-ts/core/Option";
import type { Option } from "@effect/data/Option";

const _nonNullString: Optic.Prism<string | null, string> = Optic.id<
string | null
Expand All @@ -531,8 +531,8 @@ const result2: Option<string> = pipe(null, Optic.getOption(_nonNullString)); //
The `some` method is a utility function that creates an optic that focuses on the `Some` case of an `Option` data type. This optic allows you to view and modify the value contained within the `Some` case of an `Option`.

```ts
import { pipe } from "@fp-ts/core/Function";
import * as O from "@fp-ts/core/Option";
import { pipe } from "@effect/data/Function";
import * as O from "@effect/data/Option";
import * as Optic from "@fp-ts/optic";

// This creates a prism that focuses on the 'Some' case of the 'Option<number>' object.
Expand All @@ -552,9 +552,9 @@ const updated: O.Option<number> = pipe(option, Optic.replace(_some)(23)); // ret
The `index` method creates an `Optional` optic that focuses on a specific index in a `ReadonlyArray`. The `Optional` optic allows you to view the value at the specified index, or `None` if the index does not exist. You can also use the `Optional` optic to update the value at the specified index, if it exists.

```ts
import { pipe } from "@fp-ts/core/Function";
import { pipe } from "@effect/data/Function";
import * as Optic from "@fp-ts/optic";
import type { Option } from "@fp-ts/core/Option";
import type { Option } from "@effect/data/Option";

const _index2: Optic.Optional<ReadonlyArray<number>, number> = Optic.id<
ReadonlyArray<number>
Expand All @@ -573,8 +573,8 @@ const updated3: ReadonlyArray<number> = pipe([], Optic.replace(_index2)(10)); //
The `key` method is a utility function that allows you to create an `Optional` optic that focuses on a specific key of an index signature (a type with a string index signature).

```ts
import { pipe } from "@fp-ts/core/Function";
import type { Option } from "@fp-ts/core/Option";
import { pipe } from "@effect/data/Function";
import type { Option } from "@effect/data/Option";
import * as Optic from "@fp-ts/optic";

interface Data {
Expand Down
2 changes: 1 addition & 1 deletion dtslint/ts4.7/pipeable-compose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pipe } from "@fp-ts/core/Function"
import { pipe } from "@effect/data/Function"
import type { Iso, Lens, Optional, PolyIso, PolyLens, PolyOptional, PolyPrism, Prism } from "@fp-ts/optic"

interface S { s: string }
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
}
},
"dependencies": {
"@effect/data": "^0.1.2",
"@fp-ts/core": "~0.2.1"
"@effect/data": "^0.2.0"
}
}
16 changes: 4 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/data/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/
import type { Chunk } from "@effect/data/Chunk"
import * as C from "@effect/data/Chunk"
import * as E from "@fp-ts/core/Either"
import { pipe } from "@fp-ts/core/Function"
import * as O from "@fp-ts/core/Option"
import * as E from "@effect/data/Either"
import { pipe } from "@effect/data/Function"
import * as O from "@effect/data/Option"
import type { Optional, PolyPrism, Prism } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"

Expand Down
4 changes: 2 additions & 2 deletions src/data/Either.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @since 1.0.0
*/
import type { Either } from "@fp-ts/core/Either"
import * as E from "@fp-ts/core/Either"
import type { Either } from "@effect/data/Either"
import * as E from "@effect/data/Either"
import type { PolyPrism, Prism } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"

Expand Down
6 changes: 3 additions & 3 deletions src/data/HashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @since 1.0.0
*/

import { pipe } from "@effect/data/Function"
import type { HashMap } from "@effect/data/HashMap"
import * as HM from "@effect/data/HashMap"
import { pipe } from "@fp-ts/core/Function"
import type { Option } from "@fp-ts/core/Option"
import * as O from "@fp-ts/core/Option"
import type { Option } from "@effect/data/Option"
import * as O from "@effect/data/Option"
import * as Optic from "@fp-ts/optic"
import type { At } from "@fp-ts/optic/typeclass/At"
import type { Index } from "@fp-ts/optic/typeclass/Index"
Expand Down
6 changes: 3 additions & 3 deletions src/data/Option.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @since 1.0.0
*/
import * as E from "@fp-ts/core/Either"
import type { Option } from "@fp-ts/core/Option"
import * as O from "@fp-ts/core/Option"
import * as E from "@effect/data/Either"
import type { Option } from "@effect/data/Option"
import * as O from "@effect/data/Option"
import type { Prism } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"

Expand Down
4 changes: 2 additions & 2 deletions src/data/ReadonlyArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @since 1.0.0
*/

import type { NonEmptyReadonlyArray } from "@fp-ts/core/ReadonlyArray"
import * as RA from "@fp-ts/core/ReadonlyArray"
import type { NonEmptyReadonlyArray } from "@effect/data/ReadonlyArray"
import * as RA from "@effect/data/ReadonlyArray"
import type { Iso, PolyIso } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"

Expand Down
6 changes: 3 additions & 3 deletions src/data/SortedMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @since 1.0.0
*/

import { pipe } from "@effect/data/Function"
import type { Option } from "@effect/data/Option"
import * as O from "@effect/data/Option"
import * as SM from "@effect/data/SortedMap"
import type { SortedMap } from "@effect/data/SortedMap"
import { pipe } from "@fp-ts/core/Function"
import type { Option } from "@fp-ts/core/Option"
import * as O from "@fp-ts/core/Option"
import * as Optic from "@fp-ts/optic"
import type { At } from "@fp-ts/optic/typeclass/At"
import type { Index } from "@fp-ts/optic/typeclass/Index"
Expand Down
4 changes: 2 additions & 2 deletions src/data/String.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @since 1.0.0
*/

import * as E from "@fp-ts/core/Either"
import * as String from "@fp-ts/core/String"
import * as E from "@effect/data/Either"
import * as String from "@effect/data/String"
import type { Optional } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"

Expand Down
8 changes: 4 additions & 4 deletions src/experimental.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @since 1.0.0
*/
import * as E from "@fp-ts/core/Either"
import { identity, pipe } from "@fp-ts/core/Function"
import type { Kind, TypeLambda } from "@fp-ts/core/HKT"
import type { Applicative } from "@fp-ts/core/typeclass/Applicative"
import * as E from "@effect/data/Either"
import { identity, pipe } from "@effect/data/Function"
import type { Kind, TypeLambda } from "@effect/data/HKT"
import type { Applicative } from "@effect/data/typeclass/Applicative"
import type { Lens, Optional, PolyOptional } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"

Expand Down
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* @since 1.0.0
*/
import type { Either } from "@fp-ts/core/Either"
import * as E from "@fp-ts/core/Either"
import { identity, pipe } from "@fp-ts/core/Function"
import * as O from "@fp-ts/core/Option"
import type { Option } from "@fp-ts/core/Option"
import type { Predicate, Refinement } from "@fp-ts/core/Predicate"
import * as RA from "@fp-ts/core/ReadonlyArray"
import * as RR from "@fp-ts/core/ReadonlyRecord"
import type { ReadonlyRecord } from "@fp-ts/core/ReadonlyRecord"
import * as S from "@fp-ts/core/Struct"
import type { Either } from "@effect/data/Either"
import * as E from "@effect/data/Either"
import { identity, pipe } from "@effect/data/Function"
import * as O from "@effect/data/Option"
import type { Option } from "@effect/data/Option"
import type { Predicate, Refinement } from "@effect/data/Predicate"
import * as RA from "@effect/data/ReadonlyArray"
import * as RR from "@effect/data/ReadonlyRecord"
import type { ReadonlyRecord } from "@effect/data/ReadonlyRecord"
import * as S from "@effect/data/Struct"

/**
* @since 1.0.0
Expand Down Expand Up @@ -531,7 +531,7 @@ export const cons: {
} = <A>() =>
prism<ReadonlyArray<A>, readonly [A, ReadonlyArray<A>]>(
(s) =>
RA.isNonEmpty(s) ?
RA.isNonEmptyReadonlyArray(s) ?
E.right([s[0], s.slice(1)]) :
E.left(new Error("Expected a non empty array")),
([head, tail]) => [head, ...tail]
Expand Down
4 changes: 2 additions & 2 deletions src/typeclass/At.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @since 1.0.0
*/

import type { Option } from "@fp-ts/core/Option"
import * as O from "@fp-ts/core/Option"
import type { Option } from "@effect/data/Option"
import * as O from "@effect/data/Option"
import type { Lens } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"

Expand Down
6 changes: 3 additions & 3 deletions src/typeclass/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* @since 1.0.0
*/

import * as E from "@fp-ts/core/Either"
import { pipe } from "@fp-ts/core/Function"
import type { Option } from "@fp-ts/core/Option"
import * as E from "@effect/data/Either"
import { pipe } from "@effect/data/Function"
import type { Option } from "@effect/data/Option"
import type { Optional } from "@fp-ts/optic"
import * as Optic from "@fp-ts/optic"
import type { At } from "@fp-ts/optic/typeclass/At"
Expand Down
6 changes: 3 additions & 3 deletions test/data/Chunk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Chunk } from "@effect/data/Chunk"
import * as C from "@effect/data/Chunk"
import * as E from "@fp-ts/core/Either"
import { pipe } from "@fp-ts/core/Function"
import * as O from "@fp-ts/core/Option"
import * as E from "@effect/data/Either"
import { pipe } from "@effect/data/Function"
import * as O from "@effect/data/Option"
import * as Optic from "@fp-ts/optic"
import * as ChunkOptic from "@fp-ts/optic/data/Chunk"

Expand Down
2 changes: 1 addition & 1 deletion test/data/Date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pipe } from "@fp-ts/core/Function"
import { pipe } from "@effect/data/Function"
import * as Optic from "@fp-ts/optic"
import * as D from "@fp-ts/optic/data/Date"

Expand Down
6 changes: 3 additions & 3 deletions test/data/Either.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as E from "@fp-ts/core/Either"
import { pipe } from "@fp-ts/core/Function"
import * as O from "@fp-ts/core/Option"
import * as E from "@effect/data/Either"
import { pipe } from "@effect/data/Function"
import * as O from "@effect/data/Option"
import * as Optic from "@fp-ts/optic"
import * as EitherOptic from "@fp-ts/optic/data/Either"

Expand Down
6 changes: 3 additions & 3 deletions test/data/HashMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as E from "@effect/data/Either"
import { pipe } from "@effect/data/Function"
import * as HashMap from "@effect/data/HashMap"
import * as E from "@fp-ts/core/Either"
import { pipe } from "@fp-ts/core/Function"
import * as O from "@fp-ts/core/Option"
import * as O from "@effect/data/Option"
import * as Optic from "@fp-ts/optic"
import * as HashMapOptic from "@fp-ts/optic/data/HashMap"
import * as AtOptic from "@fp-ts/optic/typeclass/At"
Expand Down
Loading

0 comments on commit d9a747d

Please sign in to comment.