Skip to content

Effect 数据类型

Effect生态系统中的Data模块通过自动实现EqualHash特征简化了值比较。这消除了手动实现的需要,使等值检查变得简单。

示例(使用Data比较结构)

import {
import Data
Data
,
import Equal
Equal
} from "effect"
const
const person1: {
readonly name: string;
readonly age: number;
}
person1
=
import Data
Data
.
const struct: <{
name: string;
age: number;
}>(a: {
name: string;
age: number;
}) => {
readonly name: string;
readonly age: number;
}

@example

import * as assert from "node:assert"
import { Data, Equal } from "effect"
const alice = Data.struct({ name: "Alice", age: 30 })
const bob = Data.struct({ name: "Bob", age: 40 })
assert.deepStrictEqual(Equal.equals(alice, alice), true)
assert.deepStrictEqual(Equal.equals(alice, Data.struct({ name: "Alice", age: 30 })), true)
assert.deepStrictEqual(Equal.equals(alice, { name: "Alice", age: 30 }), false)
assert.deepStrictEqual(Equal.equals(alice, bob), false)

@since2.0.0

struct
({
name: string
name
: "Alice",
age: number
age
: 30 })
const
const person2: {
readonly name: string;
readonly age: number;
}
person2
=
import Data
Data
.
const struct: <{
name: string;
age: number;
}>(a: {
name: string;
age: number;
}) => {
readonly name: string;
readonly age: number;
}

@example

import * as assert from "node:assert"
import { Data, Equal } from "effect"
const alice = Data.struct({ name: "Alice", age: 30 })
const bob = Data.struct({ name: "Bob", age: 40 })
assert.deepStrictEqual(Equal.equals(alice, alice), true)
assert.deepStrictEqual(Equal.equals(alice, Data.struct({ name: "Alice", age: 30 })), true)
assert.deepStrictEqual(Equal.equals(alice, { name: "Alice", age: 30 }), false)
assert.deepStrictEqual(Equal.equals(alice, bob), false)

@since2.0.0

struct
({
name: string
name
: "Alice",
age: number
age
: 30 })
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Equal
Equal
.
function equals<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(self: {
readonly name: string;
readonly age: number;
}, that: {
readonly name: string;
readonly age: number;
}): boolean (+1 overload)

@since2.0.0

equals
(
const person1: {
readonly name: string;
readonly age: number;
}
person1
,
const person2: {
readonly name: string;
readonly age: number;
}
person2
))
// Output: true

默认情况下,像Schema.Struct这样的模式不实现EqualHash特征。这意味着具有相同值的两个解码对象不会被认为相等。

示例(没有EqualHash的默认行为)

import {
import Schema
Schema
} from "effect"
import {
import Equal
Equal
} from "effect"
const
const schema: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
schema
=
import Schema
Schema
.
function Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>(fields: {
name: typeof Schema.String;
age: typeof Schema.Number;
}): Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.String
name
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
age: typeof Schema.Number
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
})
const
const decode: (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
decode
=
import Schema
Schema
.
const decode: <{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions) => (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>

@since3.10.0

decode
(
const schema: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
schema
)
const
const person1: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person1
=
const decode: (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
decode
({
name: string
name
: "Alice",
age: number
age
: 30 })
const
const person2: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person2
=
const decode: (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
decode
({
name: string
name
: "Alice",
age: number
age
: 30 })
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Equal
Equal
.
function equals<Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>, Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>>(self: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>, that: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>): boolean (+1 overload)

@since2.0.0

equals
(
const person1: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person1
,
const person2: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person2
))
// Output: false

Schema.Data函数可用于通过包含EqualHash特征来增强模式。这允许结果对象支持基于值的等值。

示例(使用Schema.Data添加等值)

import {
import Schema
Schema
} from "effect"
import {
import Equal
Equal
} from "effect"
const
const schema: Schema.Data<Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>>
schema
=
import Schema
Schema
.
const Data: <Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>, {
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(value: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}> & Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>) => Schema.Data<Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>>

Type and Encoded must extend Readonly<Record<string, any>> | ReadonlyArray<any> to be compatible with this API.

@since3.10.0

Data
(
import Schema
Schema
.
function Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>(fields: {
name: typeof Schema.String;
age: typeof Schema.Number;
}): Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.String
name
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
age: typeof Schema.Number
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
})
)
const
const decode: (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
decode
=
import Schema
Schema
.
const decode: <{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions) => (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>

@since3.10.0

decode
(
const schema: Schema.Data<Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>>
schema
)
const
const person1: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person1
=
const decode: (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
decode
({
name: string
name
: "Alice",
age: number
age
: 30 })
const
const person2: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person2
=
const decode: (i: {
readonly name: string;
readonly age: number;
}, overrideOptions?: ParseOptions) => Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
decode
({
name: string
name
: "Alice",
age: number
age
: 30 })
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Equal
Equal
.
function equals<Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>, Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>>(self: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>, that: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>): boolean (+1 overload)

@since2.0.0

equals
(
const person1: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person1
,
const person2: Effect<{
readonly name: string;
readonly age: number;
}, ParseError, never>
person2
))
// Output: true

Schema.Config函数允许您使用结构化模式解码和管理应用程序配置设置。 它确保配置数据的一致性,并为解码错误提供详细反馈。

语法

Config: <A, I extends string>(name: string, schema: Schema<A, I>) =>
Config<A>

此函数接受两个参数:

  • name:配置设置的标识符。
  • schema:描述预期数据类型和结构的模式。

它返回一个与您的应用程序配置系统集成的Config对象。

编码类型I必须扩展string,因此模式必须能够从字符串解码,这包括像Schema.StringSchema.Literal("...")Schema.NumberFromString这样的模式,可能应用了细化。

在幕后,Schema.Config遵循以下步骤:

  1. 获取值使用提供的名称(例如从环境变量)。
  2. 解码值使用给定的模式。如果值无效,解码失败。
  3. 格式化任何错误使用TreeFormatter.formatErrorSync,这有助于产生可读和详细的错误消息。

示例(解码配置值)

import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
,
import Schema
Schema
} from "effect"
// 定义期望至少4个字符的字符串的配置
const
const myConfig: Config<string>
myConfig
=
import Schema
Schema
.
const Config: <string, string>(name: string, schema: Schema.Schema<string, string, never>) => Config<string>

@since3.10.0

Config
(
"Foo",
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Pipeable.pipe<typeof Schema.String, Schema.filter<typeof Schema.String>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<typeof Schema.String>): Schema.filter<typeof Schema.String> (+21 overloads)
pipe
(
import Schema
Schema
.
const minLength: <typeof Schema.String>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>

@since3.10.0

minLength
(4))
)
const
const program: Effect.Effect<void, ConfigError, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const gen: <YieldWrap<Effect.Effect<string, ConfigError, never>>, void>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<string, ConfigError, never>>, void, never>) => Effect.Effect<void, ConfigError, never> (+1 overload)

Provides a way to write effectful code using generator functions, simplifying control flow and error handling.

When to Use

Effect.gen allows you to write code that looks and behaves like synchronous code, but it can handle asynchronous tasks, errors, and complex control flow (like loops and conditions). It helps make asynchronous code more readable and easier to manage.

The generator functions work similarly to async/await but with more explicit control over the execution of effects. You can yield* values from effects and return the final result at the end.

Example

import { Effect } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, Error> =>
discountRate === 0
? Effect.fail(new Error("Discount rate cannot be zero"))
: Effect.succeed(total - (total * discountRate) / 100)
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
export const program = Effect.gen(function* () {
const transactionAmount = yield* fetchTransactionAmount
const discountRate = yield* fetchDiscountRate
const discountedAmount = yield* applyDiscount(
transactionAmount,
discountRate
)
const finalAmount = addServiceCharge(discountedAmount)
return `Final amount to charge: ${finalAmount}`
})

@since2.0.0

gen
(function* () {
const
const foo: string
foo
= yield*
const myConfig: Config<string>
myConfig
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(`ok: ${
const foo: string
foo
}`)
})
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runSync: <void, ConfigError>(effect: Effect.Effect<void, ConfigError, never>) => void

Executes an effect synchronously, running it immediately and returning the result.

Details

This function evaluates the provided effect synchronously, returning its result directly. It is ideal for effects that do not fail or include asynchronous operations. If the effect does fail or involves async tasks, it will throw an error. Execution stops at the point of failure or asynchronous operation, making it unsuitable for effects that require asynchronous handling.

Important: Attempting to run effects that involve asynchronous operations or failures will result in exceptions being thrown, so use this function with care for purely synchronous and error-free effects.

When to Use

Use this function when:

  • You are sure that the effect will not fail or involve asynchronous operations.
  • You need a direct, synchronous result from the effect.
  • You are working within a context where asynchronous effects are not allowed.

Avoid using this function for effects that can fail or require asynchronous handling. For such cases, consider using

runPromise

or

runSyncExit

.

Example (Synchronous Logging)

import { Effect } from "effect"
const program = Effect.sync(() => {
console.log("Hello, World!")
return 1
})
const result = Effect.runSync(program)
// Output: Hello, World!
console.log(result)
// Output: 1

Example (Incorrect Usage with Failing or Async Effects)

import { Effect } from "effect"
try {
// Attempt to run an effect that fails
Effect.runSync(Effect.fail("my error"))
} catch (e) {
console.error(e)
}
// Output:
// (FiberFailure) Error: my error
try {
// Attempt to run an effect that involves async work
Effect.runSync(Effect.promise(() => Promise.resolve(1)))
} catch (e) {
console.error(e)
}
// Output:
// (FiberFailure) AsyncFiberException: Fiber #0 cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work

@seerunSyncExit for a version that returns an Exit type instead of throwing an error.

@since2.0.0

runSync
(
const program: Effect.Effect<void, ConfigError, never>
program
)

要测试配置,请执行以下命令:

测试(缺少配置数据)

Terminal window
npx tsx config.ts
# Output:
# [(Missing data at Foo: "Expected Foo to exist in the process context")]

测试(无效数据)

Terminal window
Foo=bar npx tsx config.ts
# Output:
# [(Invalid data at Foo: "a string at least 4 character(s) long
# └─ Predicate refinement failure
# └─ Expected a string at least 4 character(s) long, actual "bar"")]

测试(有效数据)

Terminal window
Foo=foobar npx tsx config.ts
# Output:
# ok: foobar

Schema.Option函数对于将Option转换为JSON可序列化格式很有用。

语法

Schema.Option(schema: Schema<A, I, R>)
输入输出
{ _tag: "None" }转换为Option.none()
{ _tag: "Some", value: I }转换为Option.some(a),其中I使用内部模式解码为A
输入输出
Option.none()转换为{ _tag: "None" }
Option.some(A)转换为{ _tag: "Some", value: I },其中A使用内部模式编码为I

示例

import {
import Schema
Schema
} from "effect"
import {
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
const
const schema: Schema.Option<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function Option<typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString): Schema.Option<typeof Schema.NumberFromString>

@since3.10.0

Option
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── OptionEncoded<string>
// ▼
type
type Encoded = {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}
Encoded
= typeof
const schema: Schema.Option<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, { readonly _tag: "None"; } | { readonly _tag: "Some"; readonly value: string; }, never>.Encoded: {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}
Encoded
// ┌─── Option<number>
// ▼
type
type Type = Option.None<number> | Option.Some<number>
Type
= typeof
const schema: Schema.Option<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, { readonly _tag: "None"; } | { readonly _tag: "Some"; readonly value: string; }, never>.Type: Option.Option<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<Option.Option<number>, {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}>(schema: Schema.Schema<Option.Option<number>, {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.Option<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}
encode
=
import Schema
Schema
.
encodeSync<Option.Option<number>, {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}>(schema: Schema.Schema<Option.Option<number>, {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}, never>, options?: ParseOptions): (a: Option.Option<number>, overrideOptions?: ParseOptions) => {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.Option<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
({
_tag: string
_tag
: "None" }))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
({
_tag: string
_tag
: "Some",
value: string
value
: "1" }))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const none: <number>() => Option.Option<number>

Represents the absence of a value by creating an empty Option.

Option.none returns an Option<never>, which is a subtype of Option<A>. This means you can use it in place of any Option<A> regardless of the type A.

Example (Creating an Option with No Value)

import { Option } from "effect"
// An Option holding no value
//
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }

@seesome for the opposite operation.

@since2.0.0

none
()))
// Output: { _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => {
readonly _tag: "None";
} | {
readonly _tag: "Some";
readonly value: string;
}
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const some: <number>(value: number) => Option.Option<number>

Wraps the given value into an Option to represent its presence.

Example (Creating an Option with a Value)

import { Option } from "effect"
// An Option holding the number 1
//
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

@seenone for the opposite operation.

@since2.0.0

some
(1)))
// Output: { _tag: 'Some', value: '1' }

Schema.OptionFromSelf函数专为Option值已经是Option格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.OptionFromSelf(schema: Schema<A, I, R>)
输入输出
Option.none()保持为Option.none()
Option.some(I)转换为Option.some(A),其中I使用内部模式解码为A
输入输出
Option.none()保持为Option.none()
Option.some(A)转换为Option.some(I),其中A使用内部模式编码为I

示例

import {
import Schema
Schema
} from "effect"
import {
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
const
const schema: Schema.OptionFromSelf<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
const OptionFromSelf: <typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString) => Schema.OptionFromSelf<typeof Schema.NumberFromString>

@since3.10.0

OptionFromSelf
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── Option<string>
// ▼
type
type Encoded = Option.None<string> | Option.Some<string>
Encoded
= typeof
const schema: Schema.OptionFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, Option<string>, never>.Encoded: Option.Option<string>
Encoded
// ┌─── Option<number>
// ▼
type
type Type = Option.None<number> | Option.Some<number>
Type
= typeof
const schema: Schema.OptionFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, Option<string>, never>.Type: Option.Option<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<Option.Option<number>, Option.Option<string>>(schema: Schema.Schema<Option.Option<number>, Option.Option<string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.OptionFromSelf<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => Option.Option<string>
encode
=
import Schema
Schema
.
encodeSync<Option.Option<number>, Option.Option<string>>(schema: Schema.Schema<Option.Option<number>, Option.Option<string>, never>, options?: ParseOptions): (a: Option.Option<number>, overrideOptions?: ParseOptions) => Option.Option<string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.OptionFromSelf<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const none: <never>() => Option.Option<never>

Represents the absence of a value by creating an empty Option.

Option.none returns an Option<never>, which is a subtype of Option<A>. This means you can use it in place of any Option<A> regardless of the type A.

Example (Creating an Option with No Value)

import { Option } from "effect"
// An Option holding no value
//
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }

@seesome for the opposite operation.

@since2.0.0

none
()))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const some: <string>(value: string) => Option.Option<string>

Wraps the given value into an Option to represent its presence.

Example (Creating an Option with a Value)

import { Option } from "effect"
// An Option holding the number 1
//
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

@seenone for the opposite operation.

@since2.0.0

some
("1")))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => Option.Option<string>
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const none: <number>() => Option.Option<number>

Represents the absence of a value by creating an empty Option.

Option.none returns an Option<never>, which is a subtype of Option<A>. This means you can use it in place of any Option<A> regardless of the type A.

Example (Creating an Option with No Value)

import { Option } from "effect"
// An Option holding no value
//
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }

@seesome for the opposite operation.

@since2.0.0

none
()))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => Option.Option<string>
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const some: <number>(value: number) => Option.Option<number>

Wraps the given value into an Option to represent its presence.

Example (Creating an Option with a Value)

import { Option } from "effect"
// An Option holding the number 1
//
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

@seenone for the opposite operation.

@since2.0.0

some
(1)))
// Output: { _id: 'Option', _tag: 'Some', value: '1' }

Schema.OptionFromUndefinedOr函数处理将undefined视为Option.none(),所有其他值根据提供的模式解释为Option.some()的情况。

语法

Schema.OptionFromUndefinedOr(schema: Schema<A, I, R>)
输入输出
undefined转换为Option.none()
I转换为Option.some(A),其中I使用内部模式解码为A
输入输出
Option.none()转换为undefined
Option.some(A)转换为I,其中A使用内部模式编码为I

示例

import {
import Schema
Schema
} from "effect"
import {
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
const
const schema: Schema.OptionFromUndefinedOr<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function OptionFromUndefinedOr<typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString): Schema.OptionFromUndefinedOr<typeof Schema.NumberFromString>

@since3.10.0

OptionFromUndefinedOr
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── string | undefined
// ▼
type
type Encoded = string | undefined
Encoded
= typeof
const schema: Schema.OptionFromUndefinedOr<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, string | undefined, never>.Encoded: string | undefined
Encoded
// ┌─── Option<number>
// ▼
type
type Type = Option.None<number> | Option.Some<number>
Type
= typeof
const schema: Schema.OptionFromUndefinedOr<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, string | undefined, never>.Type: Option.Option<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<Option.Option<number>, string | undefined>(schema: Schema.Schema<Option.Option<number>, string | undefined, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.OptionFromUndefinedOr<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | undefined
encode
=
import Schema
Schema
.
encodeSync<Option.Option<number>, string | undefined>(schema: Schema.Schema<Option.Option<number>, string | undefined, never>, options?: ParseOptions): (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | undefined
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.OptionFromUndefinedOr<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
(
var undefined
undefined
))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
("1"))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | undefined
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const none: <number>() => Option.Option<number>

Represents the absence of a value by creating an empty Option.

Option.none returns an Option<never>, which is a subtype of Option<A>. This means you can use it in place of any Option<A> regardless of the type A.

Example (Creating an Option with No Value)

import { Option } from "effect"
// An Option holding no value
//
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }

@seesome for the opposite operation.

@since2.0.0

none
()))
// Output: undefined
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | undefined
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const some: <number>(value: number) => Option.Option<number>

Wraps the given value into an Option to represent its presence.

Example (Creating an Option with a Value)

import { Option } from "effect"
// An Option holding the number 1
//
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

@seenone for the opposite operation.

@since2.0.0

some
(1)))
// Output: "1"

Schema.OptionFromNullOr函数处理将null视为Option.none(),所有其他值根据提供的模式解释为Option.some()的情况。

语法

Schema.OptionFromNullOr(schema: Schema<A, I, R>)
输入输出
null转换为Option.none()
I转换为Option.some(A),其中I使用内部模式解码为A
输入输出
Option.none()转换为null
Option.some(A)转换为I,其中A使用内部模式编码为I

示例

import {
import Schema
Schema
} from "effect"
import {
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
const
const schema: Schema.OptionFromNullOr<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function OptionFromNullOr<typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString): Schema.OptionFromNullOr<typeof Schema.NumberFromString>

@since3.10.0

OptionFromNullOr
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── string | null
// ▼
type
type Encoded = string | null
Encoded
= typeof
const schema: Schema.OptionFromNullOr<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, string | null, never>.Encoded: string | null
Encoded
// ┌─── Option<number>
// ▼
type
type Type = Option.None<number> | Option.Some<number>
Type
= typeof
const schema: Schema.OptionFromNullOr<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, string | null, never>.Type: Option.Option<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<Option.Option<number>, string | null>(schema: Schema.Schema<Option.Option<number>, string | null, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.OptionFromNullOr<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null
encode
=
import Schema
Schema
.
encodeSync<Option.Option<number>, string | null>(schema: Schema.Schema<Option.Option<number>, string | null, never>, options?: ParseOptions): (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.OptionFromNullOr<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
(null))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
("1"))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const none: <number>() => Option.Option<number>

Represents the absence of a value by creating an empty Option.

Option.none returns an Option<never>, which is a subtype of Option<A>. This means you can use it in place of any Option<A> regardless of the type A.

Example (Creating an Option with No Value)

import { Option } from "effect"
// An Option holding no value
//
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }

@seesome for the opposite operation.

@since2.0.0

none
()))
// Output: null
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const some: <number>(value: number) => Option.Option<number>

Wraps the given value into an Option to represent its presence.

Example (Creating an Option with a Value)

import { Option } from "effect"
// An Option holding the number 1
//
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

@seenone for the opposite operation.

@since2.0.0

some
(1)))
// Output: "1"

Schema.OptionFromNullishOr函数处理将nullundefined视为Option.none(),所有其他值根据提供的模式解释为Option.some()的情况。此外,它允许自定义Option.none()的编码方式(nullundefined)。

语法

Schema.OptionFromNullishOr(
schema: Schema<A, I, R>,
onNoneEncoding: null | undefined
)
输入输出
undefined转换为Option.none()
null转换为Option.none()
I转换为Option.some(A),其中I使用内部模式解码为A
输入输出
Option.none()根据用户选择(onNoneEncoding)转换为undefinednull
Option.some(A)转换为I,其中A使用内部模式编码为I

示例

import {
import Schema
Schema
} from "effect"
import {
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
const
const schema: Schema.OptionFromNullishOr<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function OptionFromNullishOr<typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString, onNoneEncoding: null | undefined): Schema.OptionFromNullishOr<typeof Schema.NumberFromString>

@since3.10.0

OptionFromNullishOr
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
,
var undefined
undefined
// Encode Option.none() as undefined
)
// ┌─── string | null | undefined
// ▼
type
type Encoded = string | null | undefined
Encoded
= typeof
const schema: Schema.OptionFromNullishOr<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, string | null | undefined, never>.Encoded: string | null | undefined
Encoded
// ┌─── Option<number>
// ▼
type
type Type = Option.None<number> | Option.Some<number>
Type
= typeof
const schema: Schema.OptionFromNullishOr<typeof Schema.NumberFromString>
schema
.
Schema<Option<number>, string | null | undefined, never>.Type: Option.Option<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<Option.Option<number>, string | null | undefined>(schema: Schema.Schema<Option.Option<number>, string | null | undefined, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.OptionFromNullishOr<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null | undefined
encode
=
import Schema
Schema
.
encodeSync<Option.Option<number>, string | null | undefined>(schema: Schema.Schema<Option.Option<number>, string | null | undefined, never>, options?: ParseOptions): (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null | undefined
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.OptionFromNullishOr<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
(null))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
(
var undefined
undefined
))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<number>
decode
("1"))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null | undefined
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const none: <number>() => Option.Option<number>

Represents the absence of a value by creating an empty Option.

Option.none returns an Option<never>, which is a subtype of Option<A>. This means you can use it in place of any Option<A> regardless of the type A.

Example (Creating an Option with No Value)

import { Option } from "effect"
// An Option holding no value
//
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }

@seesome for the opposite operation.

@since2.0.0

none
()))
// Output: undefined
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<number>, overrideOptions?: ParseOptions) => string | null | undefined
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const some: <number>(value: number) => Option.Option<number>

Wraps the given value into an Option to represent its presence.

Example (Creating an Option with a Value)

import { Option } from "effect"
// An Option holding the number 1
//
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

@seenone for the opposite operation.

@since2.0.0

some
(1)))
// Output: "1"

Schema.OptionFromNonEmptyTrimmedString模式专为处理字符串而设计,其中修剪后的空字符串被视为Option.none(),所有其他字符串都转换为Option.some()

输入输出
s: string如果s.trim().length > 0,转换为Option.some(s)
否则转换为Option.none()
输入输出
Option.none()转换为""
Option.some(s: string)转换为s

示例

import {
import Schema
Schema
,
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
// ┌─── string
// ▼
type
type Encoded = typeof Schema.OptionFromNonEmptyTrimmedString
Encoded
= typeof
import Schema
Schema
.
class OptionFromNonEmptyTrimmedString

Transforms strings into an Option type, effectively filtering out empty or whitespace-only strings by trimming them and checking their length. Returns none for invalid inputs and some for valid non-empty strings.

@example

import { Schema } from "effect"
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)(" a ")) // Option.some("a")
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("a")) // Option.some("a")

@since3.10.0

OptionFromNonEmptyTrimmedString
// ┌─── Option<string>
// ▼
type
type Type = typeof Schema.OptionFromNonEmptyTrimmedString
Type
= typeof
import Schema
Schema
.
class OptionFromNonEmptyTrimmedString

Transforms strings into an Option type, effectively filtering out empty or whitespace-only strings by trimming them and checking their length. Returns none for invalid inputs and some for valid non-empty strings.

@example

import { Schema } from "effect"
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)(" a ")) // Option.some("a")
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("a")) // Option.some("a")

@since3.10.0

OptionFromNonEmptyTrimmedString
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<string>
decode
=
import Schema
Schema
.
decodeUnknownSync<Option.Option<string>, string>(schema: Schema.Schema<Option.Option<string>, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Option.Option<string>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
import Schema
Schema
.
class OptionFromNonEmptyTrimmedString

Transforms strings into an Option type, effectively filtering out empty or whitespace-only strings by trimming them and checking their length. Returns none for invalid inputs and some for valid non-empty strings.

@example

import { Schema } from "effect"
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)(" a ")) // Option.some("a")
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("a")) // Option.some("a")

@since3.10.0

OptionFromNonEmptyTrimmedString
)
const
const encode: (a: Option.Option<string>, overrideOptions?: ParseOptions) => string
encode
=
import Schema
Schema
.
encodeSync<Option.Option<string>, string>(schema: Schema.Schema<Option.Option<string>, string, never>, options?: ParseOptions): (a: Option.Option<string>, overrideOptions?: ParseOptions) => string
export encodeSync

@since3.10.0

encodeSync
(
import Schema
Schema
.
class OptionFromNonEmptyTrimmedString

Transforms strings into an Option type, effectively filtering out empty or whitespace-only strings by trimming them and checking their length. Returns none for invalid inputs and some for valid non-empty strings.

@example

import { Schema } from "effect"
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)(" a ")) // Option.some("a")
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("a")) // Option.some("a")

@since3.10.0

OptionFromNonEmptyTrimmedString
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<string>
decode
(""))
// Output: { _id: 'Option', _tag: 'None' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<string>
decode
(" a "))
// Output: { _id: 'Option', _tag: 'Some', value: 'a' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Option.Option<string>
decode
("a"))
// Output: { _id: 'Option', _tag: 'Some', value: 'a' }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<string>, overrideOptions?: ParseOptions) => string
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const none: <string>() => Option.Option<string>

Represents the absence of a value by creating an empty Option.

Option.none returns an Option<never>, which is a subtype of Option<A>. This means you can use it in place of any Option<A> regardless of the type A.

Example (Creating an Option with No Value)

import { Option } from "effect"
// An Option holding no value
//
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }

@seesome for the opposite operation.

@since2.0.0

none
()))
// Output: ""
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Option.Option<string>, overrideOptions?: ParseOptions) => string
encode
(
import Option

@since2.0.0

@since2.0.0

Option
.
const some: <string>(value: string) => Option.Option<string>

Wraps the given value into an Option to represent its presence.

Example (Creating an Option with a Value)

import { Option } from "effect"
// An Option holding the number 1
//
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

@seenone for the opposite operation.

@since2.0.0

some
("example")))
// Output: "example"

Schema.Either函数对于将Either转换为JSON可序列化格式很有用。

语法

Schema.Either(options: {
left: Schema<LA, LI, LR>,
right: Schema<RA, RI, RR>
})
输入输出
{ _tag: "Left", left: LI }转换为Either.left(LA),其中LI使用内部left模式解码为LA
{ _tag: "Right", right: RI }转换为Either.right(RA),其中RI使用内部right模式解码为RA
输入输出
Either.left(LA)转换为{ _tag: "Left", left: LI },其中LA使用内部left模式编码为LI
Either.right(RA)转换为{ _tag: "Right", right: RI },其中RA使用内部right模式编码为RI

示例

import {
import Schema
Schema
,
import Either

@since2.0.0

@since2.0.0

Either
} from "effect"
const
const schema: Schema.Either<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
=
import Schema
Schema
.
const Either: <typeof Schema.NumberFromString, typeof Schema.Trim>({ left, right }: {
readonly left: typeof Schema.Trim;
readonly right: typeof Schema.NumberFromString;
}) => Schema.Either<typeof Schema.NumberFromString, typeof Schema.Trim>

@since3.10.0

Either
({
left: typeof Schema.Trim
left
:
import Schema
Schema
.
class Trim

This schema allows removing whitespaces from the beginning and end of a string.

@since3.10.0

Trim
,
right: typeof Schema.NumberFromString
right
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── EitherEncoded<string, string>
// ▼
type
type Encoded = {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}
Encoded
= typeof
const schema: Schema.Either<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
.
Schema<Either<number, string>, { readonly _tag: "Right"; readonly right: string; } | { readonly _tag: "Left"; readonly left: string; }, never>.Encoded: {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}
Encoded
// ┌─── Either<number, string>
// ▼
type
type Type = Either.Left<string, number> | Either.Right<string, number>
Type
= typeof
const schema: Schema.Either<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
.
Schema<Either<number, string>, { readonly _tag: "Right"; readonly right: string; } | { readonly _tag: "Left"; readonly left: string; }, never>.Type: Either.Either<number, string>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
decode
=
import Schema
Schema
.
decodeUnknownSync<Either.Either<number, string>, {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}>(schema: Schema.Schema<Either.Either<number, string>, {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.Either<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
)
const
const encode: (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}
encode
=
import Schema
Schema
.
encodeSync<Either.Either<number, string>, {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}>(schema: Schema.Schema<Either.Either<number, string>, {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}, never>, options?: ParseOptions): (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.Either<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
decode
({
_tag: string
_tag
: "Left",
left: string
left
: " a " }))
// Output: { _id: 'Either', _tag: 'Left', left: 'a' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
decode
({
_tag: string
_tag
: "Right",
right: string
right
: "1" }))
// Output: { _id: 'Either', _tag: 'Right', right: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}
encode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const left: <string>(left: string) => Either.Either<never, string>

Constructs a new Either holding a Left value. This usually represents a failure, due to the right-bias of this structure.

@since2.0.0

left
("a")))
// Output: { _tag: 'Left', left: 'a' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Right";
readonly right: string;
} | {
readonly _tag: "Left";
readonly left: string;
}
encode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const right: <number>(right: number) => Either.Either<number, never>

Constructs a new Either holding a Right value. This usually represents a successful value due to the right bias of this structure.

@since2.0.0

right
(1)))
// Output: { _tag: 'Right', right: '1' }

Schema.EitherFromSelf函数专为Either值已经是Either格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.EitherFromSelf(options: {
left: Schema<LA, LI, LR>,
right: Schema<RA, RI, RR>
})
输入输出
Either.left(LI)转换为Either.left(LA),其中LI使用内部left模式解码为LA
Either.right(RI)转换为Either.right(RA),其中RI使用内部right模式解码为RA
输入输出
Either.left(LA)转换为Either.left(LI),其中LA使用内部left模式编码为LI
Either.right(RA)转换为Either.right(RI),其中RA使用内部right模式编码为RI

示例

import {
import Schema
Schema
,
import Either

@since2.0.0

@since2.0.0

Either
} from "effect"
const
const schema: Schema.EitherFromSelf<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
=
import Schema
Schema
.
const EitherFromSelf: <typeof Schema.NumberFromString, typeof Schema.Trim>({ left, right }: {
readonly left: typeof Schema.Trim;
readonly right: typeof Schema.NumberFromString;
}) => Schema.EitherFromSelf<typeof Schema.NumberFromString, typeof Schema.Trim>

@since3.10.0

EitherFromSelf
({
left: typeof Schema.Trim
left
:
import Schema
Schema
.
class Trim

This schema allows removing whitespaces from the beginning and end of a string.

@since3.10.0

Trim
,
right: typeof Schema.NumberFromString
right
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── Either<string, string>
// ▼
type
type Encoded = Either.Left<string, string> | Either.Right<string, string>
Encoded
= typeof
const schema: Schema.EitherFromSelf<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
.
Schema<Either<number, string>, Either<string, string>, never>.Encoded: Either.Either<string, string>
Encoded
// ┌─── Either<number, string>
// ▼
type
type Type = Either.Left<string, number> | Either.Right<string, number>
Type
= typeof
const schema: Schema.EitherFromSelf<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
.
Schema<Either<number, string>, Either<string, string>, never>.Type: Either.Either<number, string>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
decode
=
import Schema
Schema
.
decodeUnknownSync<Either.Either<number, string>, Either.Either<string, string>>(schema: Schema.Schema<Either.Either<number, string>, Either.Either<string, string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.EitherFromSelf<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
)
const
const encode: (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => Either.Either<string, string>
encode
=
import Schema
Schema
.
encodeSync<Either.Either<number, string>, Either.Either<string, string>>(schema: Schema.Schema<Either.Either<number, string>, Either.Either<string, string>, never>, options?: ParseOptions): (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => Either.Either<string, string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.EitherFromSelf<typeof Schema.NumberFromString, typeof Schema.Trim>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
decode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const left: <string>(left: string) => Either.Either<never, string>

Constructs a new Either holding a Left value. This usually represents a failure, due to the right-bias of this structure.

@since2.0.0

left
(" a ")))
// Output: { _id: 'Either', _tag: 'Left', left: 'a' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, string>
decode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const right: <string>(right: string) => Either.Either<string, never>

Constructs a new Either holding a Right value. This usually represents a successful value due to the right bias of this structure.

@since2.0.0

right
("1")))
// Output: { _id: 'Either', _tag: 'Right', right: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => Either.Either<string, string>
encode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const left: <string>(left: string) => Either.Either<never, string>

Constructs a new Either holding a Left value. This usually represents a failure, due to the right-bias of this structure.

@since2.0.0

left
("a")))
// Output: { _id: 'Either', _tag: 'Left', left: 'a' }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Either.Either<number, string>, overrideOptions?: ParseOptions) => Either.Either<string, string>
encode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const right: <number>(right: number) => Either.Either<number, never>

Constructs a new Either holding a Right value. This usually represents a successful value due to the right bias of this structure.

@since2.0.0

right
(1)))
// Output: { _id: 'Either', _tag: 'Right', right: '1' }

Schema.EitherFromUnion函数专为解码和编码Either值而设计,其中leftright侧表示为不同的类型。此模式支持原始联合类型和结构化Either类型之间的转换。

语法

Schema.EitherFromUnion(options: {
left: Schema<LA, LI, LR>,
right: Schema<RA, RI, RR>
})
输入输出
LI转换为Either.left(LA),其中LI使用内部left模式解码为LA
RI转换为Either.right(RA),其中RI使用内部right模式解码为RA
输入输出
Either.left(LA)转换为LI,其中LA使用内部left模式编码为LI
Either.right(RA)转换为RI,其中RA使用内部right模式编码为RI

示例

import {
import Schema
Schema
,
import Either

@since2.0.0

@since2.0.0

Either
} from "effect"
const
const schema: Schema.EitherFromUnion<typeof Schema.NumberFromString, typeof Schema.Boolean>
schema
=
import Schema
Schema
.
const EitherFromUnion: <typeof Schema.NumberFromString, typeof Schema.Boolean>({ left, right }: {
readonly left: typeof Schema.Boolean;
readonly right: typeof Schema.NumberFromString;
}) => Schema.EitherFromUnion<typeof Schema.NumberFromString, typeof Schema.Boolean>

@example

import * as Schema from "effect/Schema"
// Schema<string | number, Either<string, number>>
Schema.EitherFromUnion({ left: Schema.String, right: Schema.Number })

@since3.10.0

EitherFromUnion
({
left: typeof Schema.Boolean
left
:
import Schema
Schema
.
class Boolean
export Boolean

@since3.10.0

Boolean
,
right: typeof Schema.NumberFromString
right
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── string | boolean
// ▼
type
type Encoded = string | boolean
Encoded
= typeof
const schema: Schema.EitherFromUnion<typeof Schema.NumberFromString, typeof Schema.Boolean>
schema
.
Schema<Either<number, boolean>, string | boolean, never>.Encoded: string | boolean
Encoded
// ┌─── Either<number, boolean>
// ▼
type
type Type = Either.Left<boolean, number> | Either.Right<boolean, number>
Type
= typeof
const schema: Schema.EitherFromUnion<typeof Schema.NumberFromString, typeof Schema.Boolean>
schema
.
Schema<Either<number, boolean>, string | boolean, never>.Type: Either.Either<number, boolean>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, boolean>
decode
=
import Schema
Schema
.
decodeUnknownSync<Either.Either<number, boolean>, string | boolean>(schema: Schema.Schema<Either.Either<number, boolean>, string | boolean, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, boolean>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.EitherFromUnion<typeof Schema.NumberFromString, typeof Schema.Boolean>
schema
)
const
const encode: (a: Either.Either<number, boolean>, overrideOptions?: ParseOptions) => string | boolean
encode
=
import Schema
Schema
.
encodeSync<Either.Either<number, boolean>, string | boolean>(schema: Schema.Schema<Either.Either<number, boolean>, string | boolean, never>, options?: ParseOptions): (a: Either.Either<number, boolean>, overrideOptions?: ParseOptions) => string | boolean
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.EitherFromUnion<typeof Schema.NumberFromString, typeof Schema.Boolean>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, boolean>
decode
(true))
// Output: { _id: 'Either', _tag: 'Left', left: true }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Either.Either<number, boolean>
decode
("1"))
// Output: { _id: 'Either', _tag: 'Right', right: 1 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Either.Either<number, boolean>, overrideOptions?: ParseOptions) => string | boolean
encode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const left: <boolean>(left: boolean) => Either.Either<never, boolean>

Constructs a new Either holding a Left value. This usually represents a failure, due to the right-bias of this structure.

@since2.0.0

left
(true)))
// Output: true
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Either.Either<number, boolean>, overrideOptions?: ParseOptions) => string | boolean
encode
(
import Either

@since2.0.0

@since2.0.0

Either
.
const right: <number>(right: number) => Either.Either<number, never>

Constructs a new Either holding a Right value. This usually represents a successful value due to the right bias of this structure.

@since2.0.0

right
(1)))
// Output: "1"

Schema.Exit函数对于将Exit转换为JSON可序列化格式很有用。

语法

Schema.Exit(options: {
failure: Schema<FA, FI, FR>,
success: Schema<SA, SI, SR>,
defect: Schema<DA, DI, DR>
})
输入输出
{ _tag: "Failure", cause: CauseEncoded<FI, DI> }转换为Exit.failCause(Cause<FA>),其中CauseEncoded<FI, DI>使用内部failuredefect模式解码为Cause<FA>
{ _tag: "Success", value: SI }转换为Exit.succeed(SA),其中SI使用内部success模式解码为SA
输入输出
Exit.failCause(Cause<FA>)转换为{ _tag: "Failure", cause: CauseEncoded<FI, DI> },其中Cause<FA>使用内部failuredefect模式编码为CauseEncoded<FI, DI>
Exit.succeed(SA)转换为{ _tag: "Success", value: SI },其中SA使用内部success模式编码为SI

示例

import {
import Schema
Schema
,
import Exit
Exit
} from "effect"
const
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
=
import Schema
Schema
.
const Exit: <typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>({ defect, failure, success }: {
readonly failure: typeof Schema.String;
readonly success: typeof Schema.NumberFromString;
readonly defect: typeof Schema.String;
}) => Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>

@since3.10.0

Exit
({
failure: typeof Schema.String
failure
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
success: typeof Schema.NumberFromString
success
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
,
defect: typeof Schema.String
defect
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
})
// ┌─── ExitEncoded<string, string, string>
// ▼
type
type Encoded = {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}
Encoded
= typeof
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
.
Schema<Exit<number, string>, { readonly _tag: "Failure"; readonly cause: CauseEncoded<string, string>; } | { readonly _tag: "Success"; readonly value: string; }, never>.Encoded: {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}
Encoded
// ┌─── Exit<number, string>
// ▼
type
type Type = Exit.Success<number, string> | Exit.Failure<number, string>
Type
= typeof
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
.
Schema<Exit<number, string>, { readonly _tag: "Failure"; readonly cause: CauseEncoded<string, string>; } | { readonly _tag: "Success"; readonly value: string; }, never>.Type: Exit.Exit<number, string>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
=
import Schema
Schema
.
decodeUnknownSync<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}>(schema: Schema.Schema<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<...>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
)
const
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}
encode
=
import Schema
Schema
.
encodeSync<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}>(schema: Schema.Schema<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}, never>, options?: ParseOptions): (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
({
_tag: string
_tag
: "Failure",
cause: {
_tag: string;
error: string;
}
cause
: {
_tag: string
_tag
: "Fail",
error: string
error
: "a" } })
)
/*
Output:
{
_id: 'Exit',
_tag: 'Failure',
cause: { _id: 'Cause', _tag: 'Fail', failure: 'a' }
}
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
({
_tag: string
_tag
: "Success",
value: string
value
: "1" }))
/*
Output:
{ _id: 'Exit', _tag: 'Success', value: 1 }
*/
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}
encode
(
import Exit
Exit
.
const fail: <string>(error: string) => Exit.Exit<never, string>

Constructs a new Exit.Failure from the specified recoverable error of type E.

@since2.0.0

fail
("a")))
/*
Output:
{ _tag: 'Failure', cause: { _tag: 'Fail', error: 'a' } }
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, string>;
} | {
readonly _tag: "Success";
readonly value: string;
}
encode
(
import Exit
Exit
.
const succeed: <number>(value: number) => Exit.Exit<number, never>

Constructs a new Exit.Success containing the specified value of type A.

@since2.0.0

succeed
(1)))
/*
Output:
{ _tag: 'Success', value: '1' }
*/

Effect提供了内置的Defect模式来处理JavaScript错误(Error实例)和其他类型的不可恢复缺陷。

  • 解码时,如果输入具有message以及可选的namestack,它会重构Error实例。
  • 编码时,它将Error实例转换为仅保留基本属性的普通对象。

这在通过网络请求传输错误或在Error对象默认不序列化的日志系统中很有用。

示例(编码和解码缺陷)

import {
import Schema
Schema
,
import Exit
Exit
} from "effect"
const
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.Defect>
schema
=
import Schema
Schema
.
const Exit: <typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.Defect>({ defect, failure, success }: {
readonly failure: typeof Schema.String;
readonly success: typeof Schema.NumberFromString;
readonly defect: typeof Schema.Defect;
}) => Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.Defect>

@since3.10.0

Exit
({
failure: typeof Schema.String
failure
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
success: typeof Schema.NumberFromString
success
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
,
defect: typeof Schema.Defect
defect
:
import Schema
Schema
.
class Defect

Defines a schema for handling JavaScript errors (Error instances) and other types of defects. It decodes objects into Error instances if they match the expected structure (i.e., have a message and optionally a name and stack), or converts other values to their string representations.

When encoding, it converts Error instances back into plain objects containing only the error's name and message, or other values into their string forms.

This is useful for serializing and deserializing errors across network boundaries where error objects do not natively serialize.

@since3.10.0

Defect
})
const
const decode: (i: {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
=
import Schema
Schema
.
decodeSync<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}>(schema: Schema.Schema<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}, never>, options?: ParseOptions): (i: {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}, overrideOptions?: ParseOptions) => Exit.Exit<...>
export decodeSync

@since3.10.0

decodeSync
(
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.Defect>
schema
)
const
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}
encode
=
import Schema
Schema
.
encodeSync<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}>(schema: Schema.Schema<Exit.Exit<number, string>, {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}, never>, options?: ParseOptions): (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.Exit<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.Defect>
schema
)
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}
encode
(
import Exit
Exit
.
const die: (defect: unknown) => Exit.Exit<never>

Constructs a new Exit.Failure from the specified unrecoverable defect.

@since2.0.0

die
(new
var Error: ErrorConstructor
new (message?: string) => Error
Error
("Message"))))
/*
Output:
{
_tag: 'Failure',
cause: { _tag: 'Die', defect: { name: 'Error', message: 'Message' } }
}
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}
encode
(
import Exit
Exit
.
const fail: <string>(error: string) => Exit.Exit<never, string>

Constructs a new Exit.Failure from the specified recoverable error of type E.

@since2.0.0

fail
("a")))
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (i: {
readonly _tag: "Failure";
readonly cause: Schema.CauseEncoded<string, unknown>;
} | {
readonly _tag: "Success";
readonly value: string;
}, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
({
_tag: "Failure"
_tag
: "Failure",
cause: Schema.CauseEncoded<string, unknown>
cause
: {
_tag: "Die"
_tag
: "Die",
defect: unknown
defect
: {
name: string
name
: "Error",
message: string
message
: "Message" } }
})
)
/*
Output:
{
_id: 'Exit',
_tag: 'Failure',
cause: {
_id: 'Cause',
_tag: 'Die',
defect: [Error: Message] { [cause]: [Object] }
}
}
*/

Schema.ExitFromSelf函数专为Exit值已经是Exit格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.ExitFromSelf(options: {
failure: Schema<FA, FI, FR>,
success: Schema<SA, SI, SR>,
defect: Schema<DA, DI, DR>
})
输入输出
Exit.failCause(Cause<FI>)转换为Exit.failCause(Cause<FA>),其中Cause<FI>使用内部failuredefect模式解码为Cause<FA>
Exit.succeed(SI)转换为Exit.succeed(SA),其中SI使用内部success模式解码为SA
输入输出
Exit.failCause(Cause<FA>)转换为Exit.failCause(Cause<FI>),其中Cause<FA>使用内部failuredefect模式解码为Cause<FI>
Exit.succeed(SA)转换为Exit.succeed(SI),其中SA使用内部success模式编码为SI

示例

import {
import Schema
Schema
,
import Exit
Exit
} from "effect"
const
const schema: Schema.ExitFromSelf<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
=
import Schema
Schema
.
const ExitFromSelf: <typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>({ defect, failure, success }: {
readonly failure: typeof Schema.String;
readonly success: typeof Schema.NumberFromString;
readonly defect: typeof Schema.String;
}) => Schema.ExitFromSelf<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>

@since3.10.0

ExitFromSelf
({
failure: typeof Schema.String
failure
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
success: typeof Schema.NumberFromString
success
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
,
defect: typeof Schema.String
defect
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
})
// ┌─── Exit<string, string>
// ▼
type
type Encoded = Exit.Success<string, string> | Exit.Failure<string, string>
Encoded
= typeof
const schema: Schema.ExitFromSelf<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
.
Schema<Exit<number, string>, Exit<string, string>, never>.Encoded: Exit.Exit<string, string>
Encoded
// ┌─── Exit<number, string>
// ▼
type
type Type = Exit.Success<number, string> | Exit.Failure<number, string>
Type
= typeof
const schema: Schema.ExitFromSelf<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
.
Schema<Exit<number, string>, Exit<string, string>, never>.Type: Exit.Exit<number, string>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
=
import Schema
Schema
.
decodeUnknownSync<Exit.Exit<number, string>, Exit.Exit<string, string>>(schema: Schema.Schema<Exit.Exit<number, string>, Exit.Exit<string, string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.ExitFromSelf<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
)
const
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => Exit.Exit<string, string>
encode
=
import Schema
Schema
.
encodeSync<Exit.Exit<number, string>, Exit.Exit<string, string>>(schema: Schema.Schema<Exit.Exit<number, string>, Exit.Exit<string, string>, never>, options?: ParseOptions): (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => Exit.Exit<string, string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.ExitFromSelf<typeof Schema.NumberFromString, typeof Schema.String, typeof Schema.String>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
(
import Exit
Exit
.
const fail: <string>(error: string) => Exit.Exit<never, string>

Constructs a new Exit.Failure from the specified recoverable error of type E.

@since2.0.0

fail
("a")))
/*
Output:
{
_id: 'Exit',
_tag: 'Failure',
cause: { _id: 'Cause', _tag: 'Fail', failure: 'a' }
}
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Exit.Exit<number, string>
decode
(
import Exit
Exit
.
const succeed: <string>(value: string) => Exit.Exit<string, never>

Constructs a new Exit.Success containing the specified value of type A.

@since2.0.0

succeed
("1")))
/*
Output:
{ _id: 'Exit', _tag: 'Success', value: 1 }
*/
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => Exit.Exit<string, string>
encode
(
import Exit
Exit
.
const fail: <string>(error: string) => Exit.Exit<never, string>

Constructs a new Exit.Failure from the specified recoverable error of type E.

@since2.0.0

fail
("a")))
/*
Output:
{
_id: 'Exit',
_tag: 'Failure',
cause: { _id: 'Cause', _tag: 'Fail', failure: 'a' }
}
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: Exit.Exit<number, string>, overrideOptions?: ParseOptions) => Exit.Exit<string, string>
encode
(
import Exit
Exit
.
const succeed: <number>(value: number) => Exit.Exit<number, never>

Constructs a new Exit.Success containing the specified value of type A.

@since2.0.0

succeed
(1)))
/*
Output:
{ _id: 'Exit', _tag: 'Success', value: '1' }
*/

Schema.ReadonlySet函数对于将ReadonlySet转换为JSON可序列化格式很有用。

语法

Schema.ReadonlySet(schema: Schema<A, I, R>)
输入输出
ReadonlyArray<I>转换为ReadonlySet<A>,其中I使用内部模式解码为A
输入输出
ReadonlySet<A>ReadonlyArray<I>,其中A使用内部模式编码为I

示例

import {
import Schema
Schema
} from "effect"
const
const schema: Schema.ReadonlySet$<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function ReadonlySet<typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString): Schema.ReadonlySet$<typeof Schema.NumberFromString>

@since3.10.0

ReadonlySet
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── readonly string[]
// ▼
type
type Encoded = readonly string[]
Encoded
= typeof
const schema: Schema.ReadonlySet$<typeof Schema.NumberFromString>
schema
.
Schema<ReadonlySet<number>, readonly string[], never>.Encoded: readonly string[]
Encoded
// ┌─── ReadonlySet<number>
// ▼
type
type Type = ReadonlySet<number>
Type
= typeof
const schema: Schema.ReadonlySet$<typeof Schema.NumberFromString>
schema
.
Schema<ReadonlySet<number>, readonly string[], never>.Type: ReadonlySet<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlySet<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<ReadonlySet<number>, readonly string[]>(schema: Schema.Schema<ReadonlySet<number>, readonly string[], never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => ReadonlySet<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.ReadonlySet$<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: ReadonlySet<number>, overrideOptions?: ParseOptions) => readonly string[]
encode
=
import Schema
Schema
.
encodeSync<ReadonlySet<number>, readonly string[]>(schema: Schema.Schema<ReadonlySet<number>, readonly string[], never>, options?: ParseOptions): (a: ReadonlySet<number>, overrideOptions?: ParseOptions) => readonly string[]
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.ReadonlySet$<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlySet<number>
decode
(["1", "2", "3"]))
// Output: Set(3) { 1, 2, 3 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: ReadonlySet<number>, overrideOptions?: ParseOptions) => readonly string[]
encode
(new
var Set: SetConstructor
new <number>(iterable?: Iterable<number> | null | undefined) => Set<number> (+1 overload)
Set
([1, 2, 3])))
// Output: [ '1', '2', '3' ]

Schema.ReadonlySetFromSelf函数专为ReadonlySet值已经是ReadonlySet格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.ReadonlySetFromSelf(schema: Schema<A, I, R>)
输入输出
ReadonlySet<I>转换为ReadonlySet<A>,其中I使用内部模式解码为A
输入输出
ReadonlySet<A>ReadonlySet<I>,其中A使用内部模式编码为I

示例

import {
import Schema
Schema
} from "effect"
const
const schema: Schema.ReadonlySetFromSelf<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
const ReadonlySetFromSelf: <typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString) => Schema.ReadonlySetFromSelf<typeof Schema.NumberFromString>

@since3.10.0

ReadonlySetFromSelf
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── ReadonlySet<string>
// ▼
type
type Encoded = ReadonlySet<string>
Encoded
= typeof
const schema: Schema.ReadonlySetFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<ReadonlySet<number>, ReadonlySet<string>, never>.Encoded: ReadonlySet<string>
Encoded
// ┌─── ReadonlySet<number>
// ▼
type
type Type = ReadonlySet<number>
Type
= typeof
const schema: Schema.ReadonlySetFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<ReadonlySet<number>, ReadonlySet<string>, never>.Type: ReadonlySet<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlySet<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<ReadonlySet<number>, ReadonlySet<string>>(schema: Schema.Schema<ReadonlySet<number>, ReadonlySet<string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => ReadonlySet<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.ReadonlySetFromSelf<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: ReadonlySet<number>, overrideOptions?: ParseOptions) => ReadonlySet<string>
encode
=
import Schema
Schema
.
encodeSync<ReadonlySet<number>, ReadonlySet<string>>(schema: Schema.Schema<ReadonlySet<number>, ReadonlySet<string>, never>, options?: ParseOptions): (a: ReadonlySet<number>, overrideOptions?: ParseOptions) => ReadonlySet<string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.ReadonlySetFromSelf<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlySet<number>
decode
(new
var Set: SetConstructor
new <string>(iterable?: Iterable<string> | null | undefined) => Set<string> (+1 overload)
Set
(["1", "2", "3"])))
// Output: Set(3) { 1, 2, 3 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: ReadonlySet<number>, overrideOptions?: ParseOptions) => ReadonlySet<string>
encode
(new
var Set: SetConstructor
new <number>(iterable?: Iterable<number> | null | undefined) => Set<number> (+1 overload)
Set
([1, 2, 3])))
// Output: Set(3) { '1', '2', '3' }

Schema.ReadonlyMap函数对于将ReadonlyMap转换为JSON可序列化格式很有用。

语法

Schema.ReadonlyMap(options: {
key: Schema<KA, KI, KR>,
value: Schema<VA, VI, VR>
})
输入输出
ReadonlyArray<readonly [KI, VI]>转换为ReadonlyMap<KA, VA>,其中KI使用内部key模式解码为KAVI使用内部value模式解码为VA
输入输出
ReadonlyMap<KA, VA>转换为ReadonlyArray<readonly [KI, VI]>,其中KA使用内部key模式解码为KIVA使用内部value模式解码为VI

示例

import {
import Schema
Schema
} from "effect"
const
const schema: Schema.ReadonlyMap$<typeof Schema.String, typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function ReadonlyMap<typeof Schema.String, typeof Schema.NumberFromString>({ key, value }: {
readonly key: typeof Schema.String;
readonly value: typeof Schema.NumberFromString;
}): Schema.ReadonlyMap$<typeof Schema.String, typeof Schema.NumberFromString>

@since3.10.0

ReadonlyMap
({
key: typeof Schema.String
key
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
value: typeof Schema.NumberFromString
value
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── readonly (readonly [string, string])[]
// ▼
type
type Encoded = readonly (readonly [string, string])[]
Encoded
= typeof
const schema: Schema.ReadonlyMap$<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<ReadonlyMap<string, number>, readonly (readonly [string, string])[], never>.Encoded: readonly (readonly [string, string])[]
Encoded
// ┌─── ReadonlyMap<string, number>
// ▼
type
type Type = ReadonlyMap<string, number>
Type
= typeof
const schema: Schema.ReadonlyMap$<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<ReadonlyMap<string, number>, readonly (readonly [string, string])[], never>.Type: ReadonlyMap<string, number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<string, number>
decode
=
import Schema
Schema
.
decodeUnknownSync<ReadonlyMap<string, number>, readonly (readonly [string, string])[]>(schema: Schema.Schema<ReadonlyMap<string, number>, readonly (readonly [string, string])[], never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<string, number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.ReadonlyMap$<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
const
const encode: (a: ReadonlyMap<string, number>, overrideOptions?: ParseOptions) => readonly (readonly [string, string])[]
encode
=
import Schema
Schema
.
encodeSync<ReadonlyMap<string, number>, readonly (readonly [string, string])[]>(schema: Schema.Schema<ReadonlyMap<string, number>, readonly (readonly [string, string])[], never>, options?: ParseOptions): (a: ReadonlyMap<string, number>, overrideOptions?: ParseOptions) => readonly (readonly [string, string])[]
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.ReadonlyMap$<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<string, number>
decode
([
["a", "2"],
["b", "2"],
["c", "3"]
])
)
// Output: Map(3) { 'a' => 2, 'b' => 2, 'c' => 3 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: ReadonlyMap<string, number>, overrideOptions?: ParseOptions) => readonly (readonly [string, string])[]
encode
(
new
var Map: MapConstructor
new <string, number>(iterable?: Iterable<readonly [string, number]> | null | undefined) => Map<string, number> (+3 overloads)
Map
([
["a", 1],
["b", 2],
["c", 3]
])
)
)
// Output: [ [ 'a', '1' ], [ 'b', '2' ], [ 'c', '3' ] ]

Schema.ReadonlyMapFromSelf函数专为ReadonlyMap值已经是ReadonlyMap格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.ReadonlyMapFromSelf(options: {
key: Schema<KA, KI, KR>,
value: Schema<VA, VI, VR>
})
输入输出
ReadonlyMap<KI, VI>转换为ReadonlyMap<KA, VA>,其中KI使用内部key模式解码为KAVI使用内部value模式解码为VA
输入输出
ReadonlyMap<KA, VA>转换为ReadonlyMap<KI, VI>,其中KA使用内部key模式解码为KIVA使用内部value模式解码为VI

示例

import {
import Schema
Schema
} from "effect"
const
const schema: Schema.ReadonlyMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
const ReadonlyMapFromSelf: <typeof Schema.String, typeof Schema.NumberFromString>({ key, value }: {
readonly key: typeof Schema.String;
readonly value: typeof Schema.NumberFromString;
}) => Schema.ReadonlyMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>

@since3.10.0

ReadonlyMapFromSelf
({
key: typeof Schema.String
key
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
value: typeof Schema.NumberFromString
value
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── ReadonlyMap<string, string>
// ▼
type
type Encoded = ReadonlyMap<string, string>
Encoded
= typeof
const schema: Schema.ReadonlyMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<ReadonlyMap<string, number>, ReadonlyMap<string, string>, never>.Encoded: ReadonlyMap<string, string>
Encoded
// ┌─── ReadonlyMap<string, number>
// ▼
type
type Type = ReadonlyMap<string, number>
Type
= typeof
const schema: Schema.ReadonlyMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<ReadonlyMap<string, number>, ReadonlyMap<string, string>, never>.Type: ReadonlyMap<string, number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<string, number>
decode
=
import Schema
Schema
.
decodeUnknownSync<ReadonlyMap<string, number>, ReadonlyMap<string, string>>(schema: Schema.Schema<ReadonlyMap<string, number>, ReadonlyMap<string, string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<string, number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.ReadonlyMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
const
const encode: (a: ReadonlyMap<string, number>, overrideOptions?: ParseOptions) => ReadonlyMap<string, string>
encode
=
import Schema
Schema
.
encodeSync<ReadonlyMap<string, number>, ReadonlyMap<string, string>>(schema: Schema.Schema<ReadonlyMap<string, number>, ReadonlyMap<string, string>, never>, options?: ParseOptions): (a: ReadonlyMap<string, number>, overrideOptions?: ParseOptions) => ReadonlyMap<string, string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.ReadonlyMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<string, number>
decode
(
new
var Map: MapConstructor
new <string, string>(iterable?: Iterable<readonly [string, string]> | null | undefined) => Map<string, string> (+3 overloads)
Map
([
["a", "2"],
["b", "2"],
["c", "3"]
])
)
)
// Output: Map(3) { 'a' => 2, 'b' => 2, 'c' => 3 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: ReadonlyMap<string, number>, overrideOptions?: ParseOptions) => ReadonlyMap<string, string>
encode
(
new
var Map: MapConstructor
new <string, number>(iterable?: Iterable<readonly [string, number]> | null | undefined) => Map<string, number> (+3 overloads)
Map
([
["a", 1],
["b", 2],
["c", 3]
])
)
)
// Output: Map(3) { 'a' => '1', 'b' => '2', 'c' => '3' }

Schema.ReadonlyMapFromRecord函数是一个实用工具,用于将ReadonlyMap转换为对象格式(其中键是字符串,值是可序列化的),反之亦然。

语法

Schema.ReadonlyMapFromRecord({
key: Schema<KA, KI, KR>,
value: Schema<VA, VI, VR>
})
输入输出
{ readonly [x: string]: VI }转换为ReadonlyMap<KA, VA>,其中x使用key模式解码为KAVI使用value模式解码为VA
输入输出
ReadonlyMap<KA, VA>转换为{ readonly [x: string]: VI },其中KA使用key模式编码为xVA使用value模式编码为VI

示例

import {
import Schema
Schema
} from "effect"
const
const schema: Schema.SchemaClass<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>
schema
=
import Schema
Schema
.
const ReadonlyMapFromRecord: <number, never, number, string, never>({ key, value }: {
key: Schema.Schema<number, string, never>;
value: Schema.Schema<number, string, never>;
}) => Schema.SchemaClass<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>

@since3.10.0

ReadonlyMapFromRecord
({
key: Schema.Schema<number, string, never>
key
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
,
value: Schema.Schema<number, string, never>
value
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── { readonly [x: string]: string; }
// ▼
type
type Encoded = {
readonly [x: string]: string;
}
Encoded
= typeof
const schema: Schema.SchemaClass<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>
schema
.
Schema<ReadonlyMap<number, number>, { readonly [x: string]: string; }, never>.Encoded: {
readonly [x: string]: string;
}
Encoded
// ┌─── ReadonlyMap<number, number>
// ▼
type
type Type = ReadonlyMap<number, number>
Type
= typeof
const schema: Schema.SchemaClass<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>
schema
.
Schema<ReadonlyMap<number, number>, { readonly [x: string]: string; }, never>.Type: ReadonlyMap<number, number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<number, number>
decode
=
import Schema
Schema
.
decodeUnknownSync<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}>(schema: Schema.Schema<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<number, number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.SchemaClass<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>
schema
)
const
const encode: (a: ReadonlyMap<number, number>, overrideOptions?: ParseOptions) => {
readonly [x: string]: string;
}
encode
=
import Schema
Schema
.
encodeSync<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}>(schema: Schema.Schema<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>, options?: ParseOptions): (a: ReadonlyMap<number, number>, overrideOptions?: ParseOptions) => {
readonly [x: string]: string;
}
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.SchemaClass<ReadonlyMap<number, number>, {
readonly [x: string]: string;
}, never>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => ReadonlyMap<number, number>
decode
({
"1": "4",
"2": "5",
"3": "6"
})
)
// Output: Map(3) { 1 => 4, 2 => 5, 3 => 6 }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: ReadonlyMap<number, number>, overrideOptions?: ParseOptions) => {
readonly [x: string]: string;
}
encode
(
new
var Map: MapConstructor
new <number, number>(iterable?: Iterable<readonly [number, number]> | null | undefined) => Map<number, number> (+3 overloads)
Map
([
[1, 4],
[2, 5],
[3, 6]
])
)
)
// Output: { '1': '4', '2': '5', '3': '6' }

Schema.HashSet函数提供了在HashSet和数组表示之间映射的方法,允许JSON序列化和反序列化。

语法

Schema.HashSet(schema: Schema<A, I, R>)
输入输出
ReadonlyArray<I>转换为HashSet<A>,其中数组中的每个元素使用模式解码为类型A
输入输出
HashSet<A>转换为ReadonlyArray<I>,其中HashSet中的每个元素使用模式编码为类型I

示例

import {
import Schema
Schema
} from "effect"
import {
import HashSet
HashSet
} from "effect"
const
const schema: Schema.HashSet<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function HashSet<typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString): Schema.HashSet<typeof Schema.NumberFromString>

@since3.10.0

HashSet
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── readonly string[]
// ▼
type
type Encoded = readonly string[]
Encoded
= typeof
const schema: Schema.HashSet<typeof Schema.NumberFromString>
schema
.
Schema<HashSet<number>, readonly string[], never>.Encoded: readonly string[]
Encoded
// ┌─── HashSet<number>
// ▼
type
type Type = HashSet.HashSet<number>
Type
= typeof
const schema: Schema.HashSet<typeof Schema.NumberFromString>
schema
.
Schema<HashSet<number>, readonly string[], never>.Type: HashSet.HashSet<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashSet.HashSet<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<HashSet.HashSet<number>, readonly string[]>(schema: Schema.Schema<HashSet.HashSet<number>, readonly string[], never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => HashSet.HashSet<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.HashSet<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: HashSet.HashSet<number>, overrideOptions?: ParseOptions) => readonly string[]
encode
=
import Schema
Schema
.
encodeSync<HashSet.HashSet<number>, readonly string[]>(schema: Schema.Schema<HashSet.HashSet<number>, readonly string[], never>, options?: ParseOptions): (a: HashSet.HashSet<number>, overrideOptions?: ParseOptions) => readonly string[]
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.HashSet<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashSet.HashSet<number>
decode
(["1", "2", "3"]))
// Output: { _id: 'HashSet', values: [ 1, 2, 3 ] }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: HashSet.HashSet<number>, overrideOptions?: ParseOptions) => readonly string[]
encode
(
import HashSet
HashSet
.
const fromIterable: <number>(elements: Iterable<number>) => HashSet.HashSet<number>

Creates a new HashSet from an iterable collection of values.

Time complexity: O(n) where n is the number of elements in the iterable

@memberofHashSet

@since2.0.0

@example

// Creating a HashSet from an Array
import { HashSet, pipe } from "effect"
console.log(
pipe(
[1, 2, 3, 4, 5, 1, 2, 3], // Array<number> is an Iterable<number>; Note the duplicates.
HashSet.fromIterable,
HashSet.toValues
)
) // Output: [1, 2, 3, 4, 5]

@example

// Creating a HashSet from a Set
import { HashSet, pipe } from "effect"
console.log(
pipe(
new Set(["apple", "banana", "orange", "apple"]), // Set<string> is an Iterable<string>
HashSet.fromIterable,
HashSet.toValues
)
) // Output: ["apple", "banana", "orange"]

@example

// Creating a HashSet from a Generator
import { HashSet } from "effect"
// Generator functions return iterables
function* fibonacci(n: number): Generator<number, void, unknown> {
let [a, b] = [0, 1]
for (let i = 0; i < n; i++) {
yield a
;[a, b] = [b, a + b]
}
}
// Create a HashSet from the first 10 Fibonacci numbers
const fibonacciSet = HashSet.fromIterable(fibonacci(10))
console.log(HashSet.toValues(fibonacciSet))
// Outputs: [0, 1, 2, 3, 5, 8, 13, 21, 34] but in unsorted order

@example

// Creating a HashSet from another HashSet
import { HashSet, pipe } from "effect"
console.log(
pipe(
// since HashSet implements the Iterable interface, we can use it to create a new HashSet
HashSet.make(1, 2, 3, 4),
HashSet.fromIterable,
HashSet.toValues // turns the HashSet back into an array
)
) // Output: [1, 2, 3, 4]

@example

// Creating a HashSet from other Effect's data structures like Chunk
import { Chunk, HashSet, pipe } from "effect"
console.log(
pipe(
Chunk.make(1, 2, 3, 4), // Iterable<number>
HashSet.fromIterable,
HashSet.toValues // turns the HashSet back into an array
)
) // Outputs: [1, 2, 3, 4]

@seeOther HashSet constructors are module:HashSet.empty module:HashSet.make

fromIterable
([1, 2, 3])))
// Output: [ '1', '2', '3' ]

Schema.HashSetFromSelf函数专为HashSet值已经是HashSet格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.HashSetFromSelf(schema: Schema<A, I, R>)
输入输出
HashSet<I>转换为HashSet<A>,使用模式将每个元素从类型I解码为类型A
输入输出
HashSet<A>转换为HashSet<I>,使用模式将每个元素从类型A编码为类型I

示例

import {
import Schema
Schema
} from "effect"
import {
import HashSet
HashSet
} from "effect"
const
const schema: Schema.HashSetFromSelf<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
const HashSetFromSelf: <typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString) => Schema.HashSetFromSelf<typeof Schema.NumberFromString>

@since3.10.0

HashSetFromSelf
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
)
// ┌─── HashSet<string>
// ▼
type
type Encoded = HashSet.HashSet<string>
Encoded
= typeof
const schema: Schema.HashSetFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<HashSet<number>, HashSet<string>, never>.Encoded: HashSet.HashSet<string>
Encoded
// ┌─── HashSet<number>
// ▼
type
type Type = HashSet.HashSet<number>
Type
= typeof
const schema: Schema.HashSetFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<HashSet<number>, HashSet<string>, never>.Type: HashSet.HashSet<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashSet.HashSet<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<HashSet.HashSet<number>, HashSet.HashSet<string>>(schema: Schema.Schema<HashSet.HashSet<number>, HashSet.HashSet<string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => HashSet.HashSet<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.HashSetFromSelf<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: HashSet.HashSet<number>, overrideOptions?: ParseOptions) => HashSet.HashSet<string>
encode
=
import Schema
Schema
.
encodeSync<HashSet.HashSet<number>, HashSet.HashSet<string>>(schema: Schema.Schema<HashSet.HashSet<number>, HashSet.HashSet<string>, never>, options?: ParseOptions): (a: HashSet.HashSet<number>, overrideOptions?: ParseOptions) => HashSet.HashSet<string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.HashSetFromSelf<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashSet.HashSet<number>
decode
(
import HashSet
HashSet
.
const fromIterable: <string>(elements: Iterable<string>) => HashSet.HashSet<string>

Creates a new HashSet from an iterable collection of values.

Time complexity: O(n) where n is the number of elements in the iterable

@memberofHashSet

@since2.0.0

@example

// Creating a HashSet from an Array
import { HashSet, pipe } from "effect"
console.log(
pipe(
[1, 2, 3, 4, 5, 1, 2, 3], // Array<number> is an Iterable<number>; Note the duplicates.
HashSet.fromIterable,
HashSet.toValues
)
) // Output: [1, 2, 3, 4, 5]

@example

// Creating a HashSet from a Set
import { HashSet, pipe } from "effect"
console.log(
pipe(
new Set(["apple", "banana", "orange", "apple"]), // Set<string> is an Iterable<string>
HashSet.fromIterable,
HashSet.toValues
)
) // Output: ["apple", "banana", "orange"]

@example

// Creating a HashSet from a Generator
import { HashSet } from "effect"
// Generator functions return iterables
function* fibonacci(n: number): Generator<number, void, unknown> {
let [a, b] = [0, 1]
for (let i = 0; i < n; i++) {
yield a
;[a, b] = [b, a + b]
}
}
// Create a HashSet from the first 10 Fibonacci numbers
const fibonacciSet = HashSet.fromIterable(fibonacci(10))
console.log(HashSet.toValues(fibonacciSet))
// Outputs: [0, 1, 2, 3, 5, 8, 13, 21, 34] but in unsorted order

@example

// Creating a HashSet from another HashSet
import { HashSet, pipe } from "effect"
console.log(
pipe(
// since HashSet implements the Iterable interface, we can use it to create a new HashSet
HashSet.make(1, 2, 3, 4),
HashSet.fromIterable,
HashSet.toValues // turns the HashSet back into an array
)
) // Output: [1, 2, 3, 4]

@example

// Creating a HashSet from other Effect's data structures like Chunk
import { Chunk, HashSet, pipe } from "effect"
console.log(
pipe(
Chunk.make(1, 2, 3, 4), // Iterable<number>
HashSet.fromIterable,
HashSet.toValues // turns the HashSet back into an array
)
) // Outputs: [1, 2, 3, 4]

@seeOther HashSet constructors are module:HashSet.empty module:HashSet.make

fromIterable
(["1", "2", "3"])))
// Output: { _id: 'HashSet', values: [ 1, 2, 3 ] }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: HashSet.HashSet<number>, overrideOptions?: ParseOptions) => HashSet.HashSet<string>
encode
(
import HashSet
HashSet
.
const fromIterable: <number>(elements: Iterable<number>) => HashSet.HashSet<number>

Creates a new HashSet from an iterable collection of values.

Time complexity: O(n) where n is the number of elements in the iterable

@memberofHashSet

@since2.0.0

@example

// Creating a HashSet from an Array
import { HashSet, pipe } from "effect"
console.log(
pipe(
[1, 2, 3, 4, 5, 1, 2, 3], // Array<number> is an Iterable<number>; Note the duplicates.
HashSet.fromIterable,
HashSet.toValues
)
) // Output: [1, 2, 3, 4, 5]

@example

// Creating a HashSet from a Set
import { HashSet, pipe } from "effect"
console.log(
pipe(
new Set(["apple", "banana", "orange", "apple"]), // Set<string> is an Iterable<string>
HashSet.fromIterable,
HashSet.toValues
)
) // Output: ["apple", "banana", "orange"]

@example

// Creating a HashSet from a Generator
import { HashSet } from "effect"
// Generator functions return iterables
function* fibonacci(n: number): Generator<number, void, unknown> {
let [a, b] = [0, 1]
for (let i = 0; i < n; i++) {
yield a
;[a, b] = [b, a + b]
}
}
// Create a HashSet from the first 10 Fibonacci numbers
const fibonacciSet = HashSet.fromIterable(fibonacci(10))
console.log(HashSet.toValues(fibonacciSet))
// Outputs: [0, 1, 2, 3, 5, 8, 13, 21, 34] but in unsorted order

@example

// Creating a HashSet from another HashSet
import { HashSet, pipe } from "effect"
console.log(
pipe(
// since HashSet implements the Iterable interface, we can use it to create a new HashSet
HashSet.make(1, 2, 3, 4),
HashSet.fromIterable,
HashSet.toValues // turns the HashSet back into an array
)
) // Output: [1, 2, 3, 4]

@example

// Creating a HashSet from other Effect's data structures like Chunk
import { Chunk, HashSet, pipe } from "effect"
console.log(
pipe(
Chunk.make(1, 2, 3, 4), // Iterable<number>
HashSet.fromIterable,
HashSet.toValues // turns the HashSet back into an array
)
) // Outputs: [1, 2, 3, 4]

@seeOther HashSet constructors are module:HashSet.empty module:HashSet.make

fromIterable
([1, 2, 3])))
// Output: { _id: 'HashSet', values: [ '1', '3', '2' ] }

Schema.HashMap函数对于将HashMap转换为JSON可序列化格式很有用。

语法

Schema.HashMap(options: {
key: Schema<KA, KI, KR>,
value: Schema<VA, VI, VR>
})
输入输出
ReadonlyArray<readonly [KI, VI]>转换为HashMap<KA, VA>,其中KI使用指定模式解码为KAVI解码为VA
输入输出
HashMap<KA, VA>转换为ReadonlyArray<readonly [KI, VI]>,其中KA使用指定模式编码为KIVA编码为VI

示例

import {
import Schema
Schema
} from "effect"
import {
import HashMap
HashMap
} from "effect"
const
const schema: Schema.HashMap<typeof Schema.String, typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
const HashMap: <typeof Schema.String, typeof Schema.NumberFromString>({ key, value }: {
readonly key: typeof Schema.String;
readonly value: typeof Schema.NumberFromString;
}) => Schema.HashMap<typeof Schema.String, typeof Schema.NumberFromString>

@since3.10.0

HashMap
({
key: typeof Schema.String
key
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
value: typeof Schema.NumberFromString
value
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── readonly (readonly [string, string])[]
// ▼
type
type Encoded = readonly (readonly [string, string])[]
Encoded
= typeof
const schema: Schema.HashMap<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<HashMap<string, number>, readonly (readonly [string, string])[], never>.Encoded: readonly (readonly [string, string])[]
Encoded
// ┌─── HashMap<string, number>
// ▼
type
type Type = HashMap.HashMap<string, number>
Type
= typeof
const schema: Schema.HashMap<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<HashMap<string, number>, readonly (readonly [string, string])[], never>.Type: HashMap.HashMap<string, number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashMap.HashMap<string, number>
decode
=
import Schema
Schema
.
decodeUnknownSync<HashMap.HashMap<string, number>, readonly (readonly [string, string])[]>(schema: Schema.Schema<HashMap.HashMap<string, number>, readonly (readonly [string, string])[], never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => HashMap.HashMap<string, number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.HashMap<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
const
const encode: (a: HashMap.HashMap<string, number>, overrideOptions?: ParseOptions) => readonly (readonly [string, string])[]
encode
=
import Schema
Schema
.
encodeSync<HashMap.HashMap<string, number>, readonly (readonly [string, string])[]>(schema: Schema.Schema<HashMap.HashMap<string, number>, readonly (readonly [string, string])[], never>, options?: ParseOptions): (a: HashMap.HashMap<string, number>, overrideOptions?: ParseOptions) => readonly (readonly [string, string])[]
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.HashMap<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashMap.HashMap<string, number>
decode
([
["a", "2"],
["b", "2"],
["c", "3"]
])
)
// Output: { _id: 'HashMap', values: [ [ 'a', 2 ], [ 'c', 3 ], [ 'b', 2 ] ] }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: HashMap.HashMap<string, number>, overrideOptions?: ParseOptions) => readonly (readonly [string, string])[]
encode
(
import HashMap
HashMap
.
const fromIterable: <string, number>(entries: Iterable<readonly [string, number]>) => HashMap.HashMap<string, number>

Creates a new HashMap from an iterable collection of key/value pairs.

@since2.0.0

fromIterable
([
["a", 1],
["b", 2],
["c", 3]
])
)
)
// Output: [ [ 'a', '1' ], [ 'c', '3' ], [ 'b', '2' ] ]

Schema.HashMapFromSelf函数专为HashMap值已经是HashMap格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.HashMapFromSelf(options: {
key: Schema<KA, KI, KR>,
value: Schema<VA, VI, VR>
})
输入输出
HashMap<KI, VI>转换为HashMap<KA, VA>,其中KI使用指定模式解码为KAVI解码为VA
输入输出
HashMap<KA, VA>转换为HashMap<KI, VI>,其中KA使用指定模式编码为KIVA编码为VI

示例

import {
import Schema
Schema
} from "effect"
import {
import HashMap
HashMap
} from "effect"
const
const schema: Schema.HashMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
const HashMapFromSelf: <typeof Schema.String, typeof Schema.NumberFromString>({ key, value }: {
readonly key: typeof Schema.String;
readonly value: typeof Schema.NumberFromString;
}) => Schema.HashMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>

@since3.10.0

HashMapFromSelf
({
key: typeof Schema.String
key
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
value: typeof Schema.NumberFromString
value
:
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
})
// ┌─── HashMap<string, string>
// ▼
type
type Encoded = HashMap.HashMap<string, string>
Encoded
= typeof
const schema: Schema.HashMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<HashMap<string, number>, HashMap<string, string>, never>.Encoded: HashMap.HashMap<string, string>
Encoded
// ┌─── HashMap<string, number>
// ▼
type
type Type = HashMap.HashMap<string, number>
Type
= typeof
const schema: Schema.HashMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
.
Schema<HashMap<string, number>, HashMap<string, string>, never>.Type: HashMap.HashMap<string, number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashMap.HashMap<string, number>
decode
=
import Schema
Schema
.
decodeUnknownSync<HashMap.HashMap<string, number>, HashMap.HashMap<string, string>>(schema: Schema.Schema<HashMap.HashMap<string, number>, HashMap.HashMap<string, string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => HashMap.HashMap<string, number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.HashMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
const
const encode: (a: HashMap.HashMap<string, number>, overrideOptions?: ParseOptions) => HashMap.HashMap<string, string>
encode
=
import Schema
Schema
.
encodeSync<HashMap.HashMap<string, number>, HashMap.HashMap<string, string>>(schema: Schema.Schema<HashMap.HashMap<string, number>, HashMap.HashMap<string, string>, never>, options?: ParseOptions): (a: HashMap.HashMap<string, number>, overrideOptions?: ParseOptions) => HashMap.HashMap<string, string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.HashMapFromSelf<typeof Schema.String, typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => HashMap.HashMap<string, number>
decode
(
import HashMap
HashMap
.
const fromIterable: <string, string>(entries: Iterable<readonly [string, string]>) => HashMap.HashMap<string, string>

Creates a new HashMap from an iterable collection of key/value pairs.

@since2.0.0

fromIterable
([
["a", "2"],
["b", "2"],
["c", "3"]
])
)
)
// Output: { _id: 'HashMap', values: [ [ 'a', 2 ], [ 'c', 3 ], [ 'b', 2 ] ] }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: HashMap.HashMap<string, number>, overrideOptions?: ParseOptions) => HashMap.HashMap<string, string>
encode
(
import HashMap
HashMap
.
const fromIterable: <string, number>(entries: Iterable<readonly [string, number]>) => HashMap.HashMap<string, number>

Creates a new HashMap from an iterable collection of key/value pairs.

@since2.0.0

fromIterable
([
["a", 1],
["b", 2],
["c", 3]
])
)
)
// Output: { _id: 'HashMap', values: [ [ 'a', '1' ], [ 'c', '3' ], [ 'b', '2' ] ] }

Schema.SortedSet函数提供了在SortedSet和数组表示之间映射的方法,允许JSON序列化和反序列化。

语法

Schema.SortedSet(schema: Schema<A, I, R>, order: Order<A>)
输入输出
ReadonlyArray<I>转换为SortedSet<A>,其中数组中的每个元素使用模式解码为类型A
输入输出
SortedSet<A>转换为ReadonlyArray<I>,其中SortedSet中的每个元素使用模式编码为类型I

示例

import {
import Schema
Schema
} from "effect"
import {
import Number
Number
,
import SortedSet
SortedSet
} from "effect"
const
const schema: Schema.SortedSet<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
function SortedSet<typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString, ordA: Order<number>): Schema.SortedSet<typeof Schema.NumberFromString>

@since3.10.0

SortedSet
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
,
import Number
Number
.
const Order: Order<number>

@memberofNumber

@since2.0.0

Order
)
// ┌─── readonly string[]
// ▼
type
type Encoded = readonly string[]
Encoded
= typeof
const schema: Schema.SortedSet<typeof Schema.NumberFromString>
schema
.
Schema<SortedSet<number>, readonly string[], never>.Encoded: readonly string[]
Encoded
// ┌─── SortedSet<number>
// ▼
type
type Type = SortedSet.SortedSet<number>
Type
= typeof
const schema: Schema.SortedSet<typeof Schema.NumberFromString>
schema
.
Schema<SortedSet<number>, readonly string[], never>.Type: SortedSet.SortedSet<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => SortedSet.SortedSet<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<SortedSet.SortedSet<number>, readonly string[]>(schema: Schema.Schema<SortedSet.SortedSet<number>, readonly string[], never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => SortedSet.SortedSet<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.SortedSet<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: SortedSet.SortedSet<number>, overrideOptions?: ParseOptions) => readonly string[]
encode
=
import Schema
Schema
.
encodeSync<SortedSet.SortedSet<number>, readonly string[]>(schema: Schema.Schema<SortedSet.SortedSet<number>, readonly string[], never>, options?: ParseOptions): (a: SortedSet.SortedSet<number>, overrideOptions?: ParseOptions) => readonly string[]
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.SortedSet<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => SortedSet.SortedSet<number>
decode
(["1", "2", "3"]))
// Output: { _id: 'SortedSet', values: [ 1, 2, 3 ] }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: SortedSet.SortedSet<number>, overrideOptions?: ParseOptions) => readonly string[]
encode
(
import SortedSet
SortedSet
.
const fromIterable: <number>(ord: Order<number>) => <A>(iterable: Iterable<A>) => SortedSet.SortedSet<A> (+1 overload)

Creates a new SortedSet from an iterable collection of values.

@since2.0.0

fromIterable
(
import Number
Number
.
const Order: Order<number>

@memberofNumber

@since2.0.0

Order
)([1, 2, 3])))
// Output: [ '1', '2', '3' ]

Schema.SortedSetFromSelf函数专为SortedSet值已经是SortedSet格式并需要根据提供的模式解码或编码同时转换内部值的场景而设计。

语法

Schema.SortedSetFromSelf(
schema: Schema<A, I, R>,
decodeOrder: Order<A>,
encodeOrder: Order<I>
)
输入输出
SortedSet<I>转换为SortedSet<A>,使用模式将每个元素从类型I解码为类型A
输入输出
SortedSet<A>转换为SortedSet<I>,使用模式将每个元素从类型A编码为类型I

示例

import {
import Schema
Schema
} from "effect"
import {
import Number
Number
,
import SortedSet
SortedSet
,
import String
String
} from "effect"
const
const schema: Schema.SortedSetFromSelf<typeof Schema.NumberFromString>
schema
=
import Schema
Schema
.
const SortedSetFromSelf: <typeof Schema.NumberFromString>(value: typeof Schema.NumberFromString, ordA: Order<number>, ordI: Order<string>) => Schema.SortedSetFromSelf<typeof Schema.NumberFromString>

@since3.10.0

SortedSetFromSelf
(
import Schema
Schema
.
class NumberFromString

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

@since3.10.0

NumberFromString
,
import Number
Number
.
const Order: Order<number>

@memberofNumber

@since2.0.0

Order
,
import String
String
.
const Order: Order<string>

@since2.0.0

Order
)
// ┌─── SortedSet<string>
// ▼
type
type Encoded = SortedSet.SortedSet<string>
Encoded
= typeof
const schema: Schema.SortedSetFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<SortedSet<number>, SortedSet<string>, never>.Encoded: SortedSet.SortedSet<string>
Encoded
// ┌─── SortedSet<number>
// ▼
type
type Type = SortedSet.SortedSet<number>
Type
= typeof
const schema: Schema.SortedSetFromSelf<typeof Schema.NumberFromString>
schema
.
Schema<SortedSet<number>, SortedSet<string>, never>.Type: SortedSet.SortedSet<number>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => SortedSet.SortedSet<number>
decode
=
import Schema
Schema
.
decodeUnknownSync<SortedSet.SortedSet<number>, SortedSet.SortedSet<string>>(schema: Schema.Schema<SortedSet.SortedSet<number>, SortedSet.SortedSet<string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => SortedSet.SortedSet<number>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.SortedSetFromSelf<typeof Schema.NumberFromString>
schema
)
const
const encode: (a: SortedSet.SortedSet<number>, overrideOptions?: ParseOptions) => SortedSet.SortedSet<string>
encode
=
import Schema
Schema
.
encodeSync<SortedSet.SortedSet<number>, SortedSet.SortedSet<string>>(schema: Schema.Schema<SortedSet.SortedSet<number>, SortedSet.SortedSet<string>, never>, options?: ParseOptions): (a: SortedSet.SortedSet<number>, overrideOptions?: ParseOptions) => SortedSet.SortedSet<string>
export encodeSync

@since3.10.0

encodeSync
(
const schema: Schema.SortedSetFromSelf<typeof Schema.NumberFromString>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => SortedSet.SortedSet<number>
decode
(
import SortedSet
SortedSet
.
const fromIterable: <string>(ord: Order<string>) => <A>(iterable: Iterable<A>) => SortedSet.SortedSet<A> (+1 overload)

Creates a new SortedSet from an iterable collection of values.

@since2.0.0

fromIterable
(
import String
String
.
const Order: Order<string>

@since2.0.0

Order
)(["1", "2", "3"])))
// Output: { _id: 'SortedSet', values: [ 1, 2, 3 ] }
// 编码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const encode: (a: SortedSet.SortedSet<number>, overrideOptions?: ParseOptions) => SortedSet.SortedSet<string>
encode
(
import SortedSet
SortedSet
.
const fromIterable: <number>(ord: Order<number>) => <A>(iterable: Iterable<A>) => SortedSet.SortedSet<A> (+1 overload)

Creates a new SortedSet from an iterable collection of values.

@since2.0.0

fromIterable
(
import Number
Number
.
const Order: Order<number>

@memberofNumber

@since2.0.0

Order
)([1, 2, 3])))
// Output: { _id: 'SortedSet', values: [ '1', '2', '3' ] }

Duration模式系列支持跨各种格式(包括hrtime、毫秒和纳秒)的持续时间值的转换和验证。

将hrtime(即[seconds: number, nanos: number])转换为Duration

示例

import {
import Schema
Schema
} from "effect"
const
const schema: typeof Schema.Duration
schema
=
import Schema
Schema
.
class Duration

A schema that converts a JSON-compatible tagged union into a Duration.

@since3.10.0

Duration
// ┌─── readonly [seconds: number, nanos: number]
// ▼
type
type Encoded = Schema.DurationEncoded | readonly [seconds: number, nanos: number]
Encoded
= typeof
const schema: typeof Schema.Duration
schema
.
Schema<Duration, DurationEncoded | readonly [seconds: number, nanos: number], never>.Encoded: Schema.DurationEncoded | readonly [seconds: number, nanos: number]
Encoded
// ┌─── Duration
// ▼
type
type Type = Duration
Type
= typeof
const schema: typeof Schema.Duration
schema
.
Schema<Duration, DurationEncoded | readonly [seconds: number, nanos: number], never>.Type: Duration
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
=
import Schema
Schema
.
decodeUnknownSync<Duration, Schema.DurationEncoded | readonly [seconds: number, nanos: number]>(schema: Schema.Schema<Duration, Schema.DurationEncoded | readonly [seconds: number, nanos: number], never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Duration
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: typeof Schema.Duration
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
([0, 0]))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 0 }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
([5000, 0]))
// Output: { _id: 'Duration', _tag: 'Nanos', hrtime: [ 5000, 0 ] }

DurationFromSelf模式旨在验证给定值是否符合Duration类型。

示例

import {
import Schema
Schema
,
import Duration
Duration
} from "effect"
const
const schema: typeof Schema.DurationFromSelf
schema
=
import Schema
Schema
.
class DurationFromSelf

@since3.10.0

DurationFromSelf
// ┌─── Duration
// ▼
type
type Encoded = Duration.Duration
Encoded
= typeof
const schema: typeof Schema.DurationFromSelf
schema
.
Schema<Duration, Duration, never>.Encoded: Duration.Duration
Encoded
// ┌─── Duration
// ▼
type
type Type = Duration.Duration
Type
= typeof
const schema: typeof Schema.DurationFromSelf
schema
.
Schema<Duration, Duration, never>.Type: Duration.Duration
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
decode
=
import Schema
Schema
.
decodeUnknownSync<Duration.Duration, Duration.Duration>(schema: Schema.Schema<Duration.Duration, Duration.Duration, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: typeof Schema.DurationFromSelf
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
decode
(
import Duration
Duration
.
const seconds: (seconds: number) => Duration.Duration

@since2.0.0

seconds
(2)))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 2000 }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
decode
(null))
/*
throws:
ParseError: Expected DurationFromSelf, actual null
*/

number转换为Duration,其中数字表示毫秒数。

示例

import {
import Schema
Schema
} from "effect"
const
const schema: typeof Schema.DurationFromMillis
schema
=
import Schema
Schema
.
class DurationFromMillis

A schema that transforms a (possibly Infinite) non negative number into a Duration. Treats the value as the number of milliseconds.

@since3.10.0

DurationFromMillis
// ┌─── number
// ▼
type
type Encoded = number
Encoded
= typeof
const schema: typeof Schema.DurationFromMillis
schema
.
Schema<Duration, number, never>.Encoded: number
Encoded
// ┌─── Duration
// ▼
type
type Type = Duration
Type
= typeof
const schema: typeof Schema.DurationFromMillis
schema
.
Schema<Duration, number, never>.Type: Duration
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
=
import Schema
Schema
.
decodeUnknownSync<Duration, number>(schema: Schema.Schema<Duration, number, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Duration
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: typeof Schema.DurationFromMillis
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
(0))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 0 }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
(5000))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 5000 }

BigInt转换为Duration,其中数字表示纳秒数。

示例

import {
import Schema
Schema
} from "effect"
const
const schema: typeof Schema.DurationFromNanos
schema
=
import Schema
Schema
.
class DurationFromNanos

A schema that transforms a non negative bigint into a Duration. Treats the value as the number of nanoseconds.

@since3.10.0

DurationFromNanos
// ┌─── bigint
// ▼
type
type Encoded = bigint
Encoded
= typeof
const schema: typeof Schema.DurationFromNanos
schema
.
Schema<Duration, bigint, never>.Encoded: bigint
Encoded
// ┌─── Duration
// ▼
type
type Type = Duration
Type
= typeof
const schema: typeof Schema.DurationFromNanos
schema
.
Schema<Duration, bigint, never>.Type: Duration
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
=
import Schema
Schema
.
decodeUnknownSync<Duration, bigint>(schema: Schema.Schema<Duration, bigint, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Duration
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: typeof Schema.DurationFromNanos
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
(0n))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 0 }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration
decode
(5000000000n))
// Output: { _id: 'Duration', _tag: 'Nanos', hrtime: [ 5, 0 ] }

Duration限制在最小值和最大值之间。

示例

import {
import Schema
Schema
,
import Duration
Duration
} from "effect"
const
const schema: Schema.transform<typeof Schema.DurationFromSelf, Schema.filter<Schema.SchemaClass<Duration.Duration, Duration.Duration, never>>>
schema
=
import Schema
Schema
.
class DurationFromSelf

@since3.10.0

DurationFromSelf
.
Pipeable.pipe<typeof Schema.DurationFromSelf, Schema.transform<typeof Schema.DurationFromSelf, Schema.filter<Schema.SchemaClass<Duration.Duration, Duration.Duration, never>>>>(this: typeof Schema.DurationFromSelf, ab: (_: typeof Schema.DurationFromSelf) => Schema.transform<typeof Schema.DurationFromSelf, Schema.filter<Schema.SchemaClass<Duration.Duration, Duration.Duration, never>>>): Schema.transform<typeof Schema.DurationFromSelf, Schema.filter<Schema.SchemaClass<Duration.Duration, Duration.Duration, never>>> (+21 overloads)
pipe
(
import Schema
Schema
.
const clampDuration: (minimum: Duration.DurationInput, maximum: Duration.DurationInput) => <S extends Schema.Schema<in out A, in out I = A, out R = never>.Any, A extends Duration.Duration>(self: S & Schema.Schema<A, Schema.Schema.Encoded<S>, Schema.Schema.Context<S>>) => Schema.transform<S, Schema.filter<Schema.SchemaClass<A>>>

Clamps a Duration between a minimum and a maximum value.

@since3.10.0

clampDuration
("5 seconds", "10 seconds")
)
// ┌─── Duration
// ▼
type
type Encoded = Duration.Duration
Encoded
= typeof
const schema: Schema.transform<typeof Schema.DurationFromSelf, Schema.filter<Schema.SchemaClass<Duration.Duration, Duration.Duration, never>>>
schema
.
Schema<Duration, Duration, never>.Encoded: Duration.Duration
Encoded
// ┌─── Duration
// ▼
type
type Type = Duration.Duration
Type
= typeof
const schema: Schema.transform<typeof Schema.DurationFromSelf, Schema.filter<Schema.SchemaClass<Duration.Duration, Duration.Duration, never>>>
schema
.
Schema<Duration, Duration, never>.Type: Duration.Duration
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
decode
=
import Schema
Schema
.
decodeUnknownSync<Duration.Duration, Duration.Duration>(schema: Schema.Schema<Duration.Duration, Duration.Duration, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.transform<typeof Schema.DurationFromSelf, Schema.filter<Schema.SchemaClass<Duration.Duration, Duration.Duration, never>>>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
decode
(
import Duration
Duration
.
const decode: (input: Duration.DurationInput) => Duration.Duration

@since2.0.0

decode
("2 seconds")))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 5000 }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
decode
(
import Duration
Duration
.
const decode: (input: Duration.DurationInput) => Duration.Duration

@since2.0.0

decode
("6 seconds")))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 6000 }
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Duration.Duration
decode
(
import Duration
Duration
.
const decode: (input: Duration.DurationInput) => Duration.Duration

@since2.0.0

decode
("11 seconds")))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 10000 }

Schema.Redacted函数专门设计用于通过将string转换为Redacted对象来处理敏感信息。 此转换确保敏感数据不会在应用程序的输出中暴露。

示例(基本Redacted模式)

import {
import Schema
Schema
} from "effect"
const
const schema: Schema.Redacted<typeof Schema.String>
schema
=
import Schema
Schema
.
function Redacted<typeof Schema.String>(value: typeof Schema.String): Schema.Redacted<typeof Schema.String>

A transformation that transform a Schema<A, I, R> into a RedactedFromSelf<A>.

@since3.10.0

Redacted
(
import Schema
Schema
.
class String
export String

@since3.10.0

String
)
// ┌─── string
// ▼
type
type Encoded = string
Encoded
= typeof
const schema: Schema.Redacted<typeof Schema.String>
schema
.
Schema<Redacted<string>, string, never>.Encoded: string
Encoded
// ┌─── Redacted<string>
// ▼
type
type Type = Redacted<string>
Type
= typeof
const schema: Schema.Redacted<typeof Schema.String>
schema
.
Schema<Redacted<string>, string, never>.Type: Redacted<string>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Redacted<string>
decode
=
import Schema
Schema
.
decodeUnknownSync<Redacted<string>, string>(schema: Schema.Schema<Redacted<string>, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Redacted<string>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.Redacted<typeof Schema.String>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Redacted<string>
decode
("keep it secret, keep it safe"))
// Output: <redacted>

需要注意的是,当成功解码Redacted时,输出会被故意模糊化(<redacted>),以防止实际的秘密在日志或控制台输出中被泄露。

示例(错误期间的暴露风险)

在下面的示例中,如果输入字符串不符合条件(例如,包含空格),生成的错误消息可能会无意中暴露输入中包含的敏感信息。

import {
import Schema
Schema
} from "effect"
import {
import Redacted
Redacted
} from "effect"
const
const schema: Schema.transform<typeof Schema.Trimmed, Schema.Redacted<typeof Schema.String>>
schema
=
import Schema
Schema
.
class Trimmed

@since3.10.0

Trimmed
.
Pipeable.pipe<typeof Schema.Trimmed, Schema.transform<typeof Schema.Trimmed, Schema.Redacted<typeof Schema.String>>>(this: typeof Schema.Trimmed, ab: (_: typeof Schema.Trimmed) => Schema.transform<typeof Schema.Trimmed, Schema.Redacted<typeof Schema.String>>): Schema.transform<typeof Schema.Trimmed, Schema.Redacted<typeof Schema.String>> (+21 overloads)
pipe
(
import Schema
Schema
.
const compose: <Schema.Redacted<typeof Schema.String>, typeof Schema.Trimmed, string>(to: Schema.Redacted<typeof Schema.String> & Schema.Schema<Redacted.Redacted<string>, string, never>) => (from: typeof Schema.Trimmed) => Schema.transform<typeof Schema.Trimmed, Schema.Redacted<typeof Schema.String>> (+7 overloads)

@since3.10.0

compose
(
import Schema
Schema
.
function Redacted<typeof Schema.String>(value: typeof Schema.String): Schema.Redacted<typeof Schema.String>

A transformation that transform a Schema<A, I, R> into a RedactedFromSelf<A>.

@since3.10.0

Redacted
(
import Schema
Schema
.
class String
export String

@since3.10.0

String
))
)
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Schema
Schema
.
const decodeUnknownEither: <Redacted.Redacted<string>, string>(schema: Schema.Schema<Redacted.Redacted<string>, string, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either<Redacted.Redacted<string>, ParseError>

@since3.10.0

decodeUnknownEither
(
const schema: Schema.transform<typeof Schema.Trimmed, Schema.Redacted<typeof Schema.String>>
schema
)(" SECRET"))
/*
{
_id: 'Either',
_tag: 'Left',
left: {
_id: 'ParseError',
message: '(Trimmed <-> (string <-> Redacted(<redacted>)))\n' +
'└─ Encoded side transformation failure\n' +
' └─ Trimmed\n' +
' └─ Predicate refinement failure\n' +
' └─ Expected Trimmed (a string with no leading or trailing whitespace), actual " SECRET"'
}
}
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Schema
Schema
.
const encodeEither: <Redacted.Redacted<string>, string>(schema: Schema.Schema<Redacted.Redacted<string>, string, never>, options?: ParseOptions) => (a: Redacted.Redacted<string>, overrideOptions?: ParseOptions) => Either<string, ParseError>

@since3.10.0

encodeEither
(
const schema: Schema.transform<typeof Schema.Trimmed, Schema.Redacted<typeof Schema.String>>
schema
)(
import Redacted
Redacted
.
const make: <string>(value: string) => Redacted.Redacted<string>

This function creates a Redacted<A> instance from a given value A, securely hiding its content.

@example

import { Redacted } from "effect"
const API_KEY = Redacted.make("1234567890")

@since3.3.0

make
(" SECRET")))
/*
{
_id: 'Either',
_tag: 'Left',
left: {
_id: 'ParseError',
message: '(Trimmed <-> (string <-> Redacted(<redacted>)))\n' +
'└─ Encoded side transformation failure\n' +
' └─ Trimmed\n' +
' └─ Predicate refinement failure\n' +
' └─ Expected Trimmed (a string with no leading or trailing whitespace), actual " SECRET"'
}
}
*/

为了减少错误消息中敏感信息泄露的风险,您可以自定义错误消息以模糊敏感细节:

示例(自定义错误消息)

import {
import Schema
Schema
} from "effect"
import {
import Redacted
Redacted
} from "effect"
const
const schema: Schema.transform<Schema.refine<string, typeof Schema.String>, Schema.Redacted<typeof Schema.String>>
schema
=
import Schema
Schema
.
class Trimmed

@since3.10.0

Trimmed
.
Annotable<refine<string, typeof String$>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.refine<string, typeof Schema.String>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "Expected Trimmed, actual <redacted>"
}).
Pipeable.pipe<Schema.refine<string, typeof Schema.String>, Schema.transform<Schema.refine<string, typeof Schema.String>, Schema.Redacted<typeof Schema.String>>>(this: Schema.refine<string, typeof Schema.String>, ab: (_: Schema.refine<string, typeof Schema.String>) => Schema.transform<Schema.refine<string, typeof Schema.String>, Schema.Redacted<typeof Schema.String>>): Schema.transform<Schema.refine<string, typeof Schema.String>, Schema.Redacted<typeof Schema.String>> (+21 overloads)
pipe
(
import Schema
Schema
.
const compose: <Schema.Redacted<typeof Schema.String>, Schema.refine<string, typeof Schema.String>, string>(to: Schema.Redacted<typeof Schema.String> & Schema.Schema<Redacted.Redacted<string>, string, never>) => (from: Schema.refine<string, typeof Schema.String>) => Schema.transform<Schema.refine<string, typeof Schema.String>, Schema.Redacted<typeof Schema.String>> (+7 overloads)

@since3.10.0

compose
(
import Schema
Schema
.
function Redacted<typeof Schema.String>(value: typeof Schema.String): Schema.Redacted<typeof Schema.String>

A transformation that transform a Schema<A, I, R> into a RedactedFromSelf<A>.

@since3.10.0

Redacted
(
import Schema
Schema
.
class String
export String

@since3.10.0

String
)))
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Schema
Schema
.
const decodeUnknownEither: <Redacted.Redacted<string>, string>(schema: Schema.Schema<Redacted.Redacted<string>, string, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either<Redacted.Redacted<string>, ParseError>

@since3.10.0

decodeUnknownEither
(
const schema: Schema.transform<Schema.refine<string, typeof Schema.String>, Schema.Redacted<typeof Schema.String>>
schema
)(" SECRET"))
/*
{
_id: 'Either',
_tag: 'Left',
left: {
_id: 'ParseError',
message: '(Trimmed <-> (string <-> Redacted(<redacted>)))\n' +
'└─ Encoded side transformation failure\n' +
' └─ Expected Trimmed, actual <redacted>'
}
}
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Schema
Schema
.
const encodeEither: <Redacted.Redacted<string>, string>(schema: Schema.Schema<Redacted.Redacted<string>, string, never>, options?: ParseOptions) => (a: Redacted.Redacted<string>, overrideOptions?: ParseOptions) => Either<string, ParseError>

@since3.10.0

encodeEither
(
const schema: Schema.transform<Schema.refine<string, typeof Schema.String>, Schema.Redacted<typeof Schema.String>>
schema
)(
import Redacted
Redacted
.
const make: <string>(value: string) => Redacted.Redacted<string>

This function creates a Redacted<A> instance from a given value A, securely hiding its content.

@example

import { Redacted } from "effect"
const API_KEY = Redacted.make("1234567890")

@since3.3.0

make
(" SECRET")))
/*
{
_id: 'Either',
_tag: 'Left',
left: {
_id: 'ParseError',
message: '(Trimmed <-> (string <-> Redacted(<redacted>)))\n' +
'└─ Encoded side transformation failure\n' +
' └─ Expected Trimmed, actual <redacted>'
}
}
*/

Schema.RedactedFromSelf模式旨在验证给定值是否符合effect库中的Redacted类型。

示例

import {
import Schema
Schema
} from "effect"
import {
import Redacted
Redacted
} from "effect"
const
const schema: Schema.RedactedFromSelf<typeof Schema.String>
schema
=
import Schema
Schema
.
const RedactedFromSelf: <typeof Schema.String>(value: typeof Schema.String) => Schema.RedactedFromSelf<typeof Schema.String>

@since3.10.0

RedactedFromSelf
(
import Schema
Schema
.
class String
export String

@since3.10.0

String
)
// ┌─── Redacted<string>
// ▼
type
type Encoded = Redacted.Redacted<string>
Encoded
= typeof
const schema: Schema.RedactedFromSelf<typeof Schema.String>
schema
.
Schema<Redacted<string>, Redacted<string>, never>.Encoded: Redacted.Redacted<string>
Encoded
// ┌─── Redacted<string>
// ▼
type
type Type = Redacted.Redacted<string>
Type
= typeof
const schema: Schema.RedactedFromSelf<typeof Schema.String>
schema
.
Schema<Redacted<string>, Redacted<string>, never>.Type: Redacted.Redacted<string>
Type
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => Redacted.Redacted<string>
decode
=
import Schema
Schema
.
decodeUnknownSync<Redacted.Redacted<string>, Redacted.Redacted<string>>(schema: Schema.Schema<Redacted.Redacted<string>, Redacted.Redacted<string>, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => Redacted.Redacted<string>
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.RedactedFromSelf<typeof Schema.String>
schema
)
// 解码示例
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Redacted.Redacted<string>
decode
(
import Redacted
Redacted
.
const make: <string>(value: string) => Redacted.Redacted<string>

This function creates a Redacted<A> instance from a given value A, securely hiding its content.

@example

import { Redacted } from "effect"
const API_KEY = Redacted.make("1234567890")

@since3.3.0

make
("mysecret")))
// Output: <redacted>
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const decode: (u: unknown, overrideOptions?: ParseOptions) => Redacted.Redacted<string>
decode
(null))
/*
throws:
ParseError: Expected Redacted(<redacted>), actual null
*/

需要注意的是,当成功解码Redacted时,输出会被故意模糊化(<redacted>),以防止实际的秘密在日志或控制台输出中被泄露。