Skip to content

Commit

Permalink
update to effect 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Apr 17, 2024
1 parent e447f94 commit c106948
Show file tree
Hide file tree
Showing 42 changed files with 2,086 additions and 1,695 deletions.
20 changes: 20 additions & 0 deletions .changeset/weak-mirrors-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@fp-ts/optic": minor
---

- update to effect 3.0.0
- remove `experimental` module
- rename `ReadonlyArray` module to `Array`
- remove `data` folder:

Before

```ts
import * as StringOptic from "@fp-ts/optic/data/String";
```

Now

```ts
import * as StringOptic from "@fp-ts/optic/String";
```
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
module.exports = {
ignorePatterns: ["build", "dist", "dtslint", "*.mjs", "docs", "*.md"],
ignorePatterns: ["build", "dist", "dtslint", "tmp", "*.mjs", "docs", "*.md"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2018,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ yarn-error.log
tmp/
build/
dist/
tmp/
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ If you also want to **become a sponsor** to ensure this library continues to imp

## Requirements

- TypeScript 5.0 or newer
- TypeScript 5.4 or newer
- The `strict` flag enabled in your `tsconfig.json` file

```
Expand Down Expand Up @@ -85,11 +85,11 @@ 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 "effect/Option";
import * as Option from "effect/Option";

interface Street {
readonly num: number;
readonly name: O.Option<string>;
readonly name: Option.Option<string>;
}
interface Address {
readonly city: string;
Expand All @@ -112,7 +112,7 @@ const from: Employee = {
city: "london",
street: {
num: 23,
name: O.some("high street"),
name: Option.some("high street"),
},
},
},
Expand All @@ -126,7 +126,7 @@ const to: Employee = {
city: "london",
street: {
num: 23,
name: O.some("High street"),
name: Option.some("High street"),
},
},
},
Expand All @@ -137,8 +137,9 @@ 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 StringOptic from "@fp-ts/optic/String";
import * as String from "effect/String";
import * as assert from "node:assert";

const _firstChar: Optic.Optional<Employee, string> = Optic.id<Employee>()
.at("company")
Expand All @@ -150,7 +151,7 @@ const _firstChar: Optic.Optional<Employee, string> = Optic.id<Employee>()

const capitalizeName = Optic.modify(_firstChar)(String.toUpperCase);

expect(capitalizeName(from)).toEqual(to);
assert.deepStrictEqual(capitalizeName(from), to);
```

# Understanding Optics
Expand All @@ -165,7 +166,7 @@ export interface Optic<
out GetError,
out SetError,
out GetPiece,
out SetWholeAfter
out SetWholeAfter,
> {
readonly getOptic: (
GetWhole: GetWhole
Expand Down Expand Up @@ -532,19 +533,19 @@ The `some` method is a utility function that creates an optic that focuses on th

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

// This creates a prism that focuses on the 'Some' case of the 'Option<number>' object.
const _some: Optic.Prism<O.Option<number>, number> = Optic.id<
O.Option<number>
const _some: Optic.Prism<Option.Option<number>, number> = Optic.id<
Option.Option<number>
>().some();

const option: O.Option<number> = O.some(42);
const option: Option.Option<number> = Option.some(42);

const result: O.Option<number> = pipe(option, Optic.getOption(_some)); // returns some(42)
const result: Option.Option<number> = pipe(option, Optic.getOption(_some)); // returns some(42)

const updated: O.Option<number> = pipe(option, Optic.replace(_some)(23)); // returns some(23)
const updated: Option.Option<number> = pipe(option, Optic.replace(_some)(23)); // returns some(23)
```

## index
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: data/ReadonlyArray.ts
nav_order: 7
title: Array.ts
nav_order: 1
parent: Modules
---

## ReadonlyArray overview
## Array overview

Added in v1.0.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/Boolean.ts
nav_order: 1
title: Boolean.ts
nav_order: 2
parent: Modules
---

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/data/Chunk.ts.md → docs/modules/Chunk.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/Chunk.ts
nav_order: 2
title: Chunk.ts
nav_order: 3
parent: Modules
---

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/data/Date.ts.md → docs/modules/Date.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/Date.ts
nav_order: 3
title: Date.ts
nav_order: 4
parent: Modules
---

Expand Down
12 changes: 6 additions & 6 deletions docs/modules/data/Either.ts.md → docs/modules/Either.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/Either.ts
nav_order: 4
title: Either.ts
nav_order: 5
parent: Modules
---

Expand Down Expand Up @@ -28,8 +28,8 @@ An optic that accesses the `Left` case of an `Either`.

```ts
export declare const left: {
<E, A>(): Prism<Either.Either<E, A>, E>
<E, A, B>(): PolyPrism<Either.Either<E, A>, Either.Either<B, A>, E, B>
<A, E>(): Prism<Either.Either<A, E>, E>
<A, E, B>(): PolyPrism<Either.Either<A, E>, Either.Either<A, B>, E, B>
}
```

Expand All @@ -43,8 +43,8 @@ An optic that accesses the `Right` case of an `Either`.

```ts
export declare const right: {
<E, A>(): Prism<Either.Either<E, A>, A>
<E, A, B>(): PolyPrism<Either.Either<E, A>, Either.Either<E, B>, A, B>
<A, E>(): Prism<Either.Either<A, E>, A>
<A, E, B>(): PolyPrism<Either.Either<A, E>, Either.Either<B, E>, A, B>
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/HashMap.ts
nav_order: 5
title: HashMap.ts
nav_order: 6
parent: Modules
---

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/data/Option.ts.md → docs/modules/Option.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/Option.ts
nav_order: 6
title: Option.ts
nav_order: 8
parent: Modules
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/SortedMap.ts
nav_order: 8
title: SortedMap.ts
nav_order: 9
parent: Modules
---

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/data/String.ts.md → docs/modules/String.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: data/String.ts
nav_order: 9
title: String.ts
nav_order: 10
parent: Modules
---

Expand Down
147 changes: 0 additions & 147 deletions docs/modules/experimental.ts.md

This file was deleted.

Loading

0 comments on commit c106948

Please sign in to comment.