@effect/schema
Advanced tools
Comparing version 0.30.1 to 0.30.2
{ | ||
"name": "@effect/schema", | ||
"version": "0.30.1", | ||
"version": "0.30.2", | ||
"license": "MIT", | ||
@@ -10,4 +10,4 @@ "repository": { | ||
"dependencies": { | ||
"@effect/data": "^0.16.0", | ||
"@effect/io": "^0.35.0", | ||
"@effect/data": "^0.16.1", | ||
"@effect/io": "^0.35.2", | ||
"fast-check": "^3.11.0" | ||
@@ -14,0 +14,0 @@ }, |
@@ -913,21 +913,2 @@ <h3 align="center"> | ||
### Access the schema for a particular key | ||
The `getPropertySignatures` function takes a `Schema<A>` and returns a new object of type `{ [K in keyof A]: Schema<A[K]> }`. The new object has properties that are the same keys as those in the original object, and each of these properties is a schema for the corresponding property in the original object. | ||
```ts | ||
import * as S from "@effect/schema/Schema"; | ||
const Person = S.struct({ | ||
name: S.string, | ||
age: S.number | ||
}); | ||
// get the schema for each property of `Person` | ||
const shape = S.getPropertySignatures(Person); | ||
shape.name; // S.string | ||
shape.age; // S.number | ||
``` | ||
## Pick | ||
@@ -1301,2 +1282,43 @@ | ||
## Interop with `@effect/data/Data` | ||
The `@effect/data/Data` module in the Effect ecosystem serves as a utility module that simplifies the process of comparing values for equality without the need for explicit implementations of the `Equal` and `Hash` interfaces. It provides convenient APIs that automatically generate default implementations for equality checks, making it easier for developers to perform equality comparisons in their applications. | ||
```ts | ||
import * as Data from "@effect/data/Data"; | ||
import * as Equal from "@effect/data/Equal"; | ||
const person1 = Data.struct({ name: "Alice", age: 30 }); | ||
const person2 = Data.struct({ name: "Alice", age: 30 }); | ||
console.log(Equal.equals(person1, person2)); // true | ||
``` | ||
You can use the `Schema.data(schema)` combinator to build a schema from an existing schema that can decode a value `A` to a value `Data<A>`: | ||
```ts | ||
/* | ||
S.Schema<{ | ||
readonly name: string; | ||
readonly age: number; | ||
}, Data.Data<{ | ||
readonly name: string; | ||
readonly age: number; | ||
}>> | ||
*/ | ||
const schema = S.data( | ||
S.struct({ | ||
name: S.string, | ||
age: S.number | ||
}) | ||
); | ||
const decode = S.decode(schema); | ||
const person1 = decode({ name: "Alice", age: 30 }); | ||
const person2 = decode({ name: "Alice", age: 30 }); | ||
console.log(Equal.equals(person1, person2)); // true | ||
``` | ||
## Option | ||
@@ -1303,0 +1325,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
917295
1629
Updated@effect/data@^0.16.1
Updated@effect/io@^0.35.2