diff --git a/.changeset/green-years-tan.md b/.changeset/green-years-tan.md new file mode 100644 index 00000000000..28941d6fa35 --- /dev/null +++ b/.changeset/green-years-tan.md @@ -0,0 +1,13 @@ +--- +"@effect/platform-node": patch +"@effect/experimental": patch +"@effect/typeclass": patch +"@effect/platform": patch +"@effect/printer": patch +"effect": patch +"@effect/sql-pg": patch +"@effect/cli": patch +"@effect/sql": patch +--- + +Wrap JSDoc @example tags with a TypeScript fence, closes #4002 diff --git a/README.md b/README.md index fadad36110d..bb0c28dc2f9 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,10 @@ Output: Output: -``` +```` * * @example +* ```ts * import { Effect } from "effect" * * console.log(Effect.runSyncExit(Effect.succeed(1))) @@ -122,8 +123,9 @@ Output: * // _tag: "Success", * // value: 1 * // } +* ``` * -``` +```` By using this utility, you can save time and maintain consistency in your JSDoc comments, especially for complex examples. diff --git a/package.json b/package.json index be1b3e7ee54..12aef4b9a51 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@changesets/cli": "^2.27.7", "@edge-runtime/vm": "^4.0.0", "@effect/build-utils": "^0.7.7", - "@effect/docgen": "^0.4.4", + "@effect/docgen": "^0.5.1", "@effect/dtslint": "^0.1.2", "@effect/eslint-plugin": "^0.2.0", "@effect/language-service": "^0.1.0", diff --git a/packages/cli/src/Options.ts b/packages/cli/src/Options.ts index 68f296ef52c..c95ec483aa4 100644 --- a/packages/cli/src/Options.ts +++ b/packages/cli/src/Options.ts @@ -154,12 +154,14 @@ export const boolean: (name: string, options?: Options.BooleanOptionsConfig) => * inputs. The input will be mapped to it's associated value during parsing. * * @example + * ```ts * import * as Options from "@effect/cli/Options" * * export const animal: Options.Options<"dog" | "cat"> = Options.choice( * "animal", * ["dog", "cat"] * ) + * ``` * * @since 1.0.0 * @category constructors @@ -174,6 +176,7 @@ export const choice: >( * inputs. The input will be mapped to it's associated value during parsing. * * @example + * ```ts * import * as Options from "@effect/cli/Options" * import * as Data from "effect/Data" * @@ -195,6 +198,7 @@ export const choice: >( * ["dog", Dog()], * ["cat", Cat()], * ]) + * ``` * * @since 1.0.0 * @category constructors diff --git a/packages/cli/src/Prompt.ts b/packages/cli/src/Prompt.ts index 4f338168cfa..a015536b5eb 100644 --- a/packages/cli/src/Prompt.ts +++ b/packages/cli/src/Prompt.ts @@ -517,6 +517,7 @@ export declare namespace All { * as an argument. * * @example + * ```ts * import * as Prompt from "@effect/cli/Prompt" * import * as NodeContext from "@effect/platform-node/NodeContext" * import * as Runtime from "@effect/platform-node/NodeRuntime" @@ -537,6 +538,7 @@ export declare namespace All { * const allWithTuple = Prompt.all([username, password]) * * const allWithRecord = Prompt.all({ username, password }) + * ``` * * @since 1.0.0 * @category collecting & elements diff --git a/packages/effect/src/Array.ts b/packages/effect/src/Array.ts index 36ecacce4b2..2802a3aff55 100644 --- a/packages/effect/src/Array.ts +++ b/packages/effect/src/Array.ts @@ -47,10 +47,12 @@ export type NonEmptyArray = [A, ...Array] * Builds a `NonEmptyArray` from an non-empty collection of elements. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.make(1, 2, 3) * assert.deepStrictEqual(result, [1, 2, 3]) + * ``` * * @category constructors * @since 2.0.0 @@ -63,10 +65,12 @@ export const make = >( * Creates a new `Array` of the specified length. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.allocate(3) * assert.deepStrictEqual(result.length, 3) + * ``` * * @category constructors * @since 2.0.0 @@ -79,9 +83,11 @@ export const allocate = (n: number): Array => new Arra * **Note**. `n` is normalized to an integer >= 1. * * @example + * ```ts * import { makeBy } from "effect/Array" * * assert.deepStrictEqual(makeBy(5, n => n * 2), [0, 2, 4, 6, 8]) + * ``` * * @category constructors * @since 2.0.0 @@ -99,9 +105,11 @@ export const makeBy = (n: number, f: (i: number) => A): NonEmptyArray => { * Return a `NonEmptyArray` containing a range of integers, including both endpoints. * * @example + * ```ts * import { range } from "effect/Array" * * assert.deepStrictEqual(range(1, 3), [1, 2, 3]) + * ``` * * @category constructors * @since 2.0.0 @@ -115,9 +123,11 @@ export const range = (start: number, end: number): NonEmptyArray => * **Note**. `n` is normalized to an integer >= 1. * * @example + * ```ts * import { Array } from "effect" * * assert.deepStrictEqual(Array.replicate("a", 3), ["a", "a", "a"]) + * ``` * * @category constructors * @since 2.0.0 @@ -133,11 +143,13 @@ export const replicate: { * Otherwise, it converts the iterable collection to an array. * * @example + * ```ts * import { Array } from "effect" * * const set = new Set([1, 2, 3]) * const result = Array.fromIterable(set) * assert.deepStrictEqual(result, [1, 2, 3]) + * ``` * * @category constructors * @since 2.0.0 @@ -149,11 +161,13 @@ export const fromIterable = (collection: Iterable): Array => * Creates a new `Array` from a value that might not be an iterable. * * @example + * ```ts * import { Array } from "effect" * * assert.deepStrictEqual(Array.ensure("a"), ["a"]) * assert.deepStrictEqual(Array.ensure(["a"]), ["a"]) * assert.deepStrictEqual(Array.ensure(["a", "b", "c"]), ["a", "b", "c"]) + * ``` * * @category constructors * @since 3.3.0 @@ -166,10 +180,12 @@ export const ensure = (self: ReadonlyArray | A): Array => Array.isArray * @param self - The record to transform. * * @example + * ```ts * import { Array } from "effect" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(Array.fromRecord(x), [["a", 1], ["b", 2], ["c", 3]]) + * ``` * * @category conversions * @since 2.0.0 @@ -180,10 +196,12 @@ export const fromRecord: (self: Readonly>) => * Converts an `Option` to an array. * * @example + * ```ts * import { Array, Option } from "effect" * * assert.deepStrictEqual(Array.fromOption(Option.some(1)), [1]) * assert.deepStrictEqual(Array.fromOption(Option.none()), []) + * ``` * * @category conversions * @since 2.0.0 @@ -194,6 +212,7 @@ export const fromOption: (self: Option) => Array = O.toArray * Matches the elements of an array, applying functions to cases of empty and non-empty arrays. * * @example + * ```ts * import { Array } from "effect" * * const match = Array.match({ @@ -202,6 +221,7 @@ export const fromOption: (self: Option) => Array = O.toArray * }) * assert.deepStrictEqual(match([]), "empty") * assert.deepStrictEqual(match([1, 2, 3]), "head: 1, tail: 2") + * ``` * * @category pattern matching * @since 2.0.0 @@ -232,6 +252,7 @@ export const match: { * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays. * * @example + * ```ts * import { Array } from "effect" * * const matchLeft = Array.matchLeft({ @@ -240,6 +261,7 @@ export const match: { * }) * assert.deepStrictEqual(matchLeft([]), "empty") * assert.deepStrictEqual(matchLeft([1, 2, 3]), "head: 1, tail: 2") + * ``` * * @category pattern matching * @since 2.0.0 @@ -270,6 +292,7 @@ export const matchLeft: { * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays. * * @example + * ```ts * import { Array } from "effect" * * const matchRight = Array.matchRight({ @@ -278,6 +301,7 @@ export const matchLeft: { * }) * assert.deepStrictEqual(matchRight([]), "empty") * assert.deepStrictEqual(matchRight([1, 2, 3]), "init: 2, last: 3") + * ``` * * @category pattern matching * @since 2.0.0 @@ -311,11 +335,13 @@ export const matchRight: { * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`. * * @example + * ```ts * import { Array } from "effect" * * const original = [2, 3, 4]; * const result = Array.prepend(original, 1); * assert.deepStrictEqual(result, [1, 2, 3, 4]); + * ``` * * @category concatenating * @since 2.0.0 @@ -330,12 +356,14 @@ export const prepend: { * If either array is non-empty, the result is also a non-empty array. * * @example + * ```ts * import { Array } from "effect" * * const prefix = [0, 1]; * const array = [2, 3]; * const result = Array.prependAll(array, prefix); * assert.deepStrictEqual(result, [0, 1, 2, 3]); + * ``` * * @category concatenating * @since 2.0.0 @@ -356,11 +384,13 @@ export const prependAll: { * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`. * * @example + * ```ts * import { Array } from "effect" * * const original = [1, 2, 3]; * const result = Array.append(original, 4); * assert.deepStrictEqual(result, [1, 2, 3, 4]); + * ``` * * @category concatenating * @since 2.0.0 @@ -395,6 +425,7 @@ export const appendAll: { * a value through a series of transformations. * * @example + * ```ts * import { Array } from "effect"; * * const numbers = [1, 2, 3, 4] @@ -406,6 +437,7 @@ export const appendAll: { * // and adds each element of the array to this accumulator one by one, * // keeping track of the cumulative sum after each addition. * // Each of these sums is captured in the resulting array. + * ``` * * @category folding * @since 2.0.0 @@ -429,11 +461,13 @@ export const scan: { * a value through a series of transformations. * * @example + * ```ts * import { Array } from "effect"; * * const numbers = [1, 2, 3, 4] * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value) * assert.deepStrictEqual(result, [10, 9, 7, 4, 0]) + * ``` * * @category folding * @since 2.0.0 @@ -457,10 +491,12 @@ export const scanRight: { * @param self - The value to check. * * @example + * ```ts * import { isArray } from "effect/Array" * * assert.deepStrictEqual(isArray(null), false); * assert.deepStrictEqual(isArray([1, 2, 3]), true); + * ``` * * @category guards * @since 2.0.0 @@ -476,10 +512,12 @@ export const isArray: { * @param self - The `Array` to check. * * @example + * ```ts * import { isEmptyArray } from "effect/Array" * * assert.deepStrictEqual(isEmptyArray([]), true); * assert.deepStrictEqual(isEmptyArray([1, 2, 3]), false); + * ``` * * @category guards * @since 2.0.0 @@ -492,10 +530,12 @@ export const isEmptyArray = (self: Array): self is [] => self.length === 0 * @param self - The `ReadonlyArray` to check. * * @example + * ```ts * import { isEmptyReadonlyArray } from "effect/Array" * * assert.deepStrictEqual(isEmptyReadonlyArray([]), true); * assert.deepStrictEqual(isEmptyReadonlyArray([1, 2, 3]), false); + * ``` * * @category guards * @since 2.0.0 @@ -510,10 +550,12 @@ export const isEmptyReadonlyArray: (self: ReadonlyArray) => self is readon * @param self - The `Array` to check. * * @example + * ```ts * import { isNonEmptyArray } from "effect/Array" * * assert.deepStrictEqual(isNonEmptyArray([]), false); * assert.deepStrictEqual(isNonEmptyArray([1, 2, 3]), true); + * ``` * * @category guards * @since 2.0.0 @@ -528,10 +570,12 @@ export const isNonEmptyArray: (self: Array) => self is NonEmptyArray = * @param self - The `ReadonlyArray` to check. * * @example + * ```ts * import { isNonEmptyReadonlyArray } from "effect/Array" * * assert.deepStrictEqual(isNonEmptyReadonlyArray([]), false); * assert.deepStrictEqual(isNonEmptyReadonlyArray([1, 2, 3]), true); + * ``` * * @category guards * @since 2.0.0 @@ -586,10 +630,12 @@ export const unsafeGet: { * Return a tuple containing the first element, and a new `Array` of the remaining elements, if any. * * @example + * ```ts * import { Array } from "effect"; * * const result = Array.unprepend([1, 2, 3, 4]) * assert.deepStrictEqual(result, [1, [2, 3, 4]]) + * ``` * * @category splitting * @since 2.0.0 @@ -602,10 +648,12 @@ export const unprepend = ( * Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element. * * @example + * ```ts * import { Array } from "effect"; * * const result = Array.unappend([1, 2, 3, 4]) * assert.deepStrictEqual(result, [[1, 2, 3], 4]) + * ``` * * @category splitting * @since 2.0.0 @@ -626,10 +674,12 @@ export const head: (self: ReadonlyArray) => Option = get(0) * Get the first element of a non empty array. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.headNonEmpty([1, 2, 3, 4]) * assert.deepStrictEqual(result, 1) + * ``` * * @category getters * @since 2.0.0 @@ -649,10 +699,12 @@ export const last = (self: ReadonlyArray): Option => * Get the last element of a non empty array. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.lastNonEmpty([1, 2, 3, 4]) * assert.deepStrictEqual(result, 4) + * ``` * * @category getters * @since 2.0.0 @@ -674,10 +726,12 @@ export const tail = (self: Iterable): Option> => { * Get all but the first element of a `NonEmptyReadonlyArray`. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.tailNonEmpty([1, 2, 3, 4]) * assert.deepStrictEqual(result, [2, 3, 4]) + * ``` * * @category getters * @since 2.0.0 @@ -699,10 +753,12 @@ export const init = (self: Iterable): Option> => { * Get all but the last element of a non empty array, creating a new array. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.initNonEmpty([1, 2, 3, 4]) * assert.deepStrictEqual(result, [1, 2, 3]) + * ``` * * @category getters * @since 2.0.0 @@ -715,11 +771,13 @@ export const initNonEmpty = (self: NonEmptyReadonlyArray): Array => sel * **Note**. `n` is normalized to a non negative integer. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.take(numbers, 3) * assert.deepStrictEqual(result, [1, 2, 3]) + * ``` * * @category getters * @since 2.0.0 @@ -738,11 +796,13 @@ export const take: { * **Note**. `n` is normalized to a non negative integer. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.takeRight(numbers, 3) * assert.deepStrictEqual(result, [3, 4, 5]) + * ``` * * @category getters * @since 2.0.0 @@ -760,6 +820,7 @@ export const takeRight: { * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 3, 2, 4, 1, 2] @@ -771,6 +832,7 @@ export const takeRight: { * // - The next element (`3`) is also less than `4`, so it adds `3`. * // - The next element (`2`) is again less than `4`, so it adds `2`. * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result. + * ``` * * @category getters * @since 2.0.0 @@ -835,11 +897,13 @@ export const span: { * **Note**. `n` is normalized to a non negative integer. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.drop(numbers, 2) * assert.deepStrictEqual(result, [3, 4, 5]) + * ``` * * @category getters * @since 2.0.0 @@ -858,11 +922,13 @@ export const drop: { * **Note**. `n` is normalized to a non negative integer. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.dropRight(numbers, 2) * assert.deepStrictEqual(result, [1, 2, 3]) + * ``` * * @category getters * @since 2.0.0 @@ -879,11 +945,13 @@ export const dropRight: { * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.dropWhile(numbers, x => x < 4) * assert.deepStrictEqual(result, [4, 5]) + * ``` * * @category getters * @since 2.0.0 @@ -901,11 +969,13 @@ export const dropWhile: { * Return the first index for which a predicate holds. * * @example + * ```ts * import { Array, Option } from "effect" * * const numbers = [5, 3, 8, 9] * const result = Array.findFirstIndex(numbers, x => x > 5) * assert.deepStrictEqual(result, Option.some(2)) + * ``` * * @category elements * @since 2.0.0 @@ -928,11 +998,13 @@ export const findFirstIndex: { * Return the last index for which a predicate holds. * * @example + * ```ts * import { Array, Option } from "effect" * * const numbers = [1, 3, 8, 9] * const result = Array.findLastIndex(numbers, x => x < 5) * assert.deepStrictEqual(result, Option.some(1)) + * ``` * * @category elements * @since 2.0.0 @@ -955,11 +1027,13 @@ export const findLastIndex: { * predicate, or `None` if no such element exists. * * @example + * ```ts * import { Array, Option } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.findFirst(numbers, x => x > 3) * assert.deepStrictEqual(result, Option.some(4)) + * ``` * * @category elements * @since 2.0.0 @@ -978,11 +1052,13 @@ export const findFirst: { * Returns an `Option` containing the found element, or `Option.none` if no element matches. * * @example + * ```ts * import { Array, Option } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.findLast(numbers, n => n % 2 === 0) * assert.deepStrictEqual(result, Option.some(4)) + * ``` * * @category elements * @since 2.0.0 @@ -1020,11 +1096,13 @@ export const findLast: { * or return `None` if the index is out of bounds. * * @example + * ```ts * import { Array, Option } from "effect" * * const letters = ['a', 'b', 'c', 'e'] * const result = Array.insertAt(letters, 3, 'd') * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e'])) + * ``` * * @since 2.0.0 */ @@ -1046,11 +1124,13 @@ export const insertAt: { * or return a copy of the input if the index is out of bounds. * * @example + * ```ts * import { Array } from "effect" * * const letters = ['a', 'b', 'c', 'd'] * const result = Array.replace(letters, 1, 'z') * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd']) + * ``` * * @since 2.0.0 */ @@ -1072,11 +1152,13 @@ export const replace: { * Replaces an element in an array with the given value, returning an option of the updated array. * * @example + * ```ts * import { Array, Option } from "effect" * * const numbers = [1, 2, 3] * const result = Array.replaceOption(numbers, 1, 4) * assert.deepStrictEqual(result, Option.some([1, 4, 3])) + * ``` * * @since 2.0.0 */ @@ -1100,11 +1182,13 @@ export const replaceOption: { * or return a copy of the input if the index is out of bounds. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4] * const result = Array.modify(numbers, 2, (n) => n * 2) * assert.deepStrictEqual(result, [1, 2, 6, 4]) + * ``` * * @since 2.0.0 */ @@ -1129,6 +1213,7 @@ export const modify: { * or return `None` if the index is out of bounds. * * @example + * ```ts * import { Array, Option } from "effect" * * const numbers = [1, 2, 3, 4] @@ -1137,6 +1222,7 @@ export const modify: { * * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2) * assert.deepStrictEqual(outOfBoundsResult, Option.none()) + * ``` * * @since 2.0.0 */ @@ -1166,6 +1252,7 @@ export const modifyOption: { * or return a copy of the input if the index is out of bounds. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4] @@ -1174,6 +1261,7 @@ export const modifyOption: { * * const outOfBoundsResult = Array.remove(numbers, 5) * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4]) + * ``` * * @since 2.0.0 */ @@ -1193,11 +1281,13 @@ export const remove: { * Reverse an `Iterable`, creating a new `Array`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4] * const result = Array.reverse(numbers) * assert.deepStrictEqual(result, [4, 3, 2, 1]) + * ``` * * @category elements * @since 2.0.0 @@ -1232,6 +1322,7 @@ export const sort: { * order defines how those values should be sorted. * * @example + * ```ts * import { Array, Order } from "effect" * * const strings = ["aaa", "b", "cc"] @@ -1242,6 +1333,7 @@ export const sort: { * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length` * // converts each string into its length, and the `Order.number` specifies that the lengths should * // be sorted in ascending order. + * ``` * * @since 2.0.0 * @category elements @@ -1265,6 +1357,7 @@ export const sortWith: { * second order if the first comparison is equal, and so on. * * @example + * ```ts * import { Array, Order } from "effect" * * const users = [ @@ -1287,6 +1380,7 @@ export const sortWith: { * // Explanation: * // The array of users is sorted first by age in ascending order. When ages are equal, * // the users are further sorted by name in ascending order. + * ``` * * @category sorting * @since 2.0.0 @@ -1312,12 +1406,14 @@ export const sortBy = | NonEmptyReadonlyArray>( * longer `Iterable` are discarded. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2, 3] * const array2 = ['a', 'b'] * const result = Array.zip(array1, array2) * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']]) + * ``` * * @category zipping * @since 2.0.0 @@ -1337,12 +1433,14 @@ export const zip: { * input `Iterable` is short, excess elements of the longer `Iterable` are discarded. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2, 3] * const array2 = [4, 5, 6] * const result = Array.zipWith(array1, array2, (a, b) => a + b) * assert.deepStrictEqual(result, [5, 7, 9]) + * ``` * * @category zipping * @since 2.0.0 @@ -1370,10 +1468,12 @@ export const zipWith: { * This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.unzip([[1, "a"], [2, "b"], [3, "c"]]) * assert.deepStrictEqual(result, [[1, 2, 3], ['a', 'b', 'c']]) + * ``` * * @since 2.0.0 */ @@ -1400,11 +1500,13 @@ export const unzip: | NonEmptyReadonlyA * If the input is a non-empty array, the result is also a non-empty array. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] * const result = Array.intersperse(numbers, 0) * assert.deepStrictEqual(result, [1, 0, 2, 0, 3]) + * ``` * * @since 2.0.0 */ @@ -1434,10 +1536,12 @@ export const intersperse: { * Apply a function to the head, creating a new `NonEmptyReadonlyArray`. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10) * assert.deepStrictEqual(result, [10, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -1456,10 +1560,12 @@ export const modifyNonEmptyHead: { * Change the head, creating a new `NonEmptyReadonlyArray`. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.setNonEmptyHead([1, 2, 3], 10) * assert.deepStrictEqual(result, [10, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -1475,10 +1581,12 @@ export const setNonEmptyHead: { * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2) * assert.deepStrictEqual(result, [1, 2, 6]) + * ``` * * @since 2.0.0 */ @@ -1495,10 +1603,12 @@ export const modifyNonEmptyLast: { * Change the last element, creating a new `NonEmptyReadonlyArray`. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.setNonEmptyLast([1, 2, 3], 4) * assert.deepStrictEqual(result, [1, 2, 4]) + * ``` * * @since 2.0.0 */ @@ -1515,11 +1625,13 @@ export const setNonEmptyLast: { * If the input is a non-empty array, the result is also a non-empty array. * * @example + * ```ts * import { Array } from "effect" * * const letters = ['a', 'b', 'c', 'd'] * const result = Array.rotate(letters, 2) * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b']) + * ``` * * @since 2.0.0 */ @@ -1549,6 +1661,7 @@ export const rotate: { * Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4] @@ -1556,6 +1669,7 @@ export const rotate: { * const containsNumber = Array.containsWith(isEquivalent) * const result = containsNumber(3)(numbers) * assert.deepStrictEqual(result, true) + * ``` * * @category elements * @since 2.0.0 @@ -1579,11 +1693,13 @@ const _equivalence = Equal.equivalence() * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`. * * @example + * ```ts * import { Array } from "effect" * * const letters = ['a', 'b', 'c', 'd'] * const result = Array.contains('c')(letters) * assert.deepStrictEqual(result, true) + * ``` * * @category elements * @since 2.0.0 @@ -1599,6 +1715,7 @@ export const contains: { * value and the rest of the `Array`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] @@ -1609,6 +1726,7 @@ export const contains: { * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array. * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`, * // resulting in a new array `[2, 4, 6, 8, 10]`. + * ``` * * @since 2.0.0 */ @@ -1648,11 +1766,13 @@ export const chop: { * The value of `n` can be `0`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.splitAt(numbers, 3) * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]]) + * ``` * * @category splitting * @since 2.0.0 @@ -1677,10 +1797,12 @@ export const splitAt: { * The value of `n` must be `>= 1`. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.splitNonEmptyAt(["a", "b", "c", "d", "e"], 3) * assert.deepStrictEqual(result, [["a", "b", "c"], ["d", "e"]]) + * ``` * * @category splitting * @since 2.0.0 @@ -1699,11 +1821,13 @@ export const splitNonEmptyAt: { * Splits this iterable into `n` equally sized arrays. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5, 6, 7, 8] * const result = Array.split(numbers, 3) * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]]) + * ``` * * @since 2.0.0 * @category splitting @@ -1721,11 +1845,13 @@ export const split: { * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const result = Array.splitWhere(numbers, n => n > 3) * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]]) + * ``` * * @category splitting * @since 2.0.0 @@ -1745,11 +1871,13 @@ export const splitWhere: { * Copies an array. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] * const copy = Array.copy(numbers) * assert.deepStrictEqual(copy, [1, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -1765,11 +1893,13 @@ export const copy: { * If `n` is less than or equal to 0, the returned array will be an empty array. * * @example + * ```ts * import { Array } from "effect" * * const arr = [1, 2, 3] * const result = Array.pad(arr, 6, 0) * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0]) + * ``` * * @since 3.8.4 */ @@ -1803,6 +1933,7 @@ export const pad: { * whenever `n` evenly divides the length of `self`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3, 4, 5] @@ -1814,6 +1945,7 @@ export const pad: { * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2, * // the last chunk contains the remaining elements. * // The result is `[[1, 2], [3, 4], [5]]`. + * ``` * * @category splitting * @since 2.0.0 @@ -1838,10 +1970,12 @@ export const chunksOf: { * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y) * assert.deepStrictEqual(result, [["a", "a"], ["b", "b", "b"], ["c"], ["a"]]) + * ``` * * @category grouping * @since 2.0.0 @@ -1872,10 +2006,12 @@ export const groupWith: { * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s. * * @example + * ```ts * import { Array } from "effect" * * const result = Array.group([1, 1, 2, 2, 2, 3, 1]) * assert.deepStrictEqual(result, [[1, 1], [2, 2, 2], [3], [1]]) + * ``` * * @category grouping * @since 2.0.0 @@ -1889,6 +2025,7 @@ export const group: (self: NonEmptyReadonlyArray) => NonEmptyArray(self: NonEmptyReadonlyArray) => NonEmptyArray a === b) * assert.deepStrictEqual(union, [1, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -1975,12 +2115,14 @@ export const unionWith: { * Creates a union of two arrays, removing duplicates. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2] * const array2 = [2, 3] * const result = Array.union(array1, array2) * assert.deepStrictEqual(result, [1, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -2000,6 +2142,7 @@ export const union: { * The order and references of result values are determined by the first `Iterable`. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }] @@ -2007,6 +2150,7 @@ export const union: { * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id * const result = Array.intersectionWith(isEquivalent)(array2)(array1) * assert.deepStrictEqual(result, [{ id: 1 }, { id: 3 }]) + * ``` * * @since 2.0.0 */ @@ -2026,12 +2170,14 @@ export const intersectionWith = (isEquivalent: (self: A, that: A) => boolean) * The order and references of result values are determined by the first `Iterable`. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2, 3] * const array2 = [3, 4, 1] * const result = Array.intersection(array1, array2) * assert.deepStrictEqual(result, [1, 3]) + * ``` * * @since 2.0.0 */ @@ -2045,12 +2191,14 @@ export const intersection: { * The order and references of result values are determined by the first `Iterable`. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2, 3] * const array2 = [2, 3, 4] * const difference = Array.differenceWith((a, b) => a === b)(array1, array2) * assert.deepStrictEqual(difference, [1]) + * ``` * * @since 2.0.0 */ @@ -2070,12 +2218,14 @@ export const differenceWith = (isEquivalent: (self: A, that: A) => boolean): * The order and references of result values are determined by the first `Iterable`. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2, 3] * const array2 = [2, 3, 4] * const difference = Array.difference(array1, array2) * assert.deepStrictEqual(difference, [1]) + * ``` * * @since 2.0.0 */ @@ -2192,12 +2342,14 @@ export const flatMap: { * arrays is collapsed into a single, flat array. * * @example + * ```ts * import { Array } from "effect"; * * const nestedArrays = [[1, 2], [], [3, 4], [], [5, 6]] * const result = Array.flatten(nestedArrays) * * assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6]); + * ``` * * @category sequencing * @since 2.0.0 @@ -2211,6 +2363,7 @@ export const flatten: >>(self: S) => * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass. * * @example + * ```ts * import { Array, Option } from "effect"; * * const data = [1, 2, 3, 4, 5]; @@ -2218,6 +2371,7 @@ export const flatten: >>(self: S) => * const result = Array.filterMap(data, evenSquares); * * assert.deepStrictEqual(result, [4, 16]); + * ``` * * @category filtering * @since 2.0.0 @@ -2246,6 +2400,7 @@ export const filterMap: { * This is useful when you need to transform an array but only up to the point where a certain condition holds true. * * @example + * ```ts * import { Array, Option } from "effect"; * * const data = [2, 4, 5]; @@ -2253,6 +2408,7 @@ export const filterMap: { * const result = Array.filterMapWhile(data, toSquareTillOdd); * * assert.deepStrictEqual(result, [4, 16]); + * ``` * * @category filtering * @since 2.0.0 @@ -2282,6 +2438,7 @@ export const filterMapWhile: { * into successes and failures. * * @example + * ```ts * import { Array, Either } from "effect"; * * const data = [1, 2, 3, 4, 5] @@ -2294,6 +2451,7 @@ export const filterMapWhile: { * [1, 3, 5], * [2, 4] * ]) + * ``` * * @category filtering * @since 2.0.0 @@ -2323,12 +2481,14 @@ export const partitionMap: { * Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array. * * @example + * ```ts * import { Array, Option } from "effect" * * assert.deepStrictEqual( * Array.getSomes([Option.some(1), Option.none(), Option.some(2)]), * [1, 2] * ) + * ``` * * @category filtering * @since 2.0.0 @@ -2342,12 +2502,14 @@ export const getSomes: >, X = any>( * Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array. * * @example + * ```ts * import { Array, Either } from "effect" * * assert.deepStrictEqual( * Array.getLefts([Either.right(1), Either.left("err"), Either.right(2)]), * ["err"] * ) + * ``` * * @category filtering * @since 2.0.0 @@ -2367,12 +2529,14 @@ export const getLefts = >>(self: T): Array n % 2 === 0) * assert.deepStrictEqual(result, [[1, 3], [2, 4]]) + * ``` * * @category filtering * @since 2.0.0 @@ -2471,11 +2637,13 @@ export const separate: >>( * Reduces an array from the left. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] * const result = Array.reduce(numbers, 0, (acc, n) => acc + n) * assert.deepStrictEqual(result, 6) + * ``` * * @category folding * @since 2.0.0 @@ -2493,11 +2661,13 @@ export const reduce: { * Reduces an array from the right. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n) * assert.deepStrictEqual(result, 6) + * ``` * * @category folding * @since 2.0.0 @@ -2515,12 +2685,14 @@ export const reduceRight: { * Lifts a predicate into an array. * * @example + * ```ts * import { Array } from "effect" * * const isEven = (n: number) => n % 2 === 0 * const to = Array.liftPredicate(isEven) * assert.deepStrictEqual(to(1), []) * assert.deepStrictEqual(to(2), [2]) + * ``` * * @category lifting * @since 2.0.0 @@ -2558,6 +2730,7 @@ export const liftNullable = , B>( * Maps over an array and flattens the result, removing null and undefined values. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] @@ -2568,6 +2741,7 @@ export const liftNullable = , B>( * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened * // to remove null values, resulting in [1, 3]. + * ``` * * @category sequencing * @since 2.0.0 @@ -2587,6 +2761,7 @@ export const flatMapNullable: { * If the `Either` is a right, it returns an array with the right value. * * @example + * ```ts * import { Array, Either } from "effect" * * const parseNumber = (s: string): Either.Either => @@ -2604,6 +2779,7 @@ export const flatMapNullable: { * // The function parseNumber is lifted to return an array. * // When parsing "42", it returns an Either.left with the number 42, resulting in [42]. * // When parsing "not a number", it returns an Either.right with an error, resulting in an empty array []. + * ``` * * @category lifting * @since 2.0.0 @@ -2656,6 +2832,7 @@ export const some: { * Extends an array with a function that maps each subarray to a value. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] @@ -2667,6 +2844,7 @@ export const some: { * // The subarrays are: [1, 2, 3], [2, 3], [3]. * // The lengths are: 3, 2, 1. * // Therefore, the result is [3, 2, 1]. + * ``` * * @since 2.0.0 */ @@ -2682,10 +2860,12 @@ export const extend: { * Finds the minimum element in an array based on a comparator. * * @example + * ```ts * import { Array, Order } from "effect" * * const min = Array.min([3, 1, 2], Order.number) * assert.deepStrictEqual(min, 1) + * ``` * * @since 2.0.0 */ @@ -2698,10 +2878,12 @@ export const min: { * Finds the maximum element in an array based on a comparator. * * @example + * ```ts * import { Array, Order } from "effect" * * const max = Array.max([3, 1, 2], Order.number) * assert.deepStrictEqual(max, 3) + * ``` * * @since 2.0.0 */ @@ -2741,12 +2923,14 @@ export const getOrder: (O: Order.Order) => Order.Order> = * Creates an equivalence relation for arrays. * * @example + * ```ts * import { Array } from "effect" * * const numbers1 = [1, 2, 3] * const numbers2 = [1, 2, 3] * const eq = Array.getEquivalence((a, b) => a === b) * assert.deepStrictEqual(eq(numbers1, numbers2), true) + * ``` * * @category instances * @since 2.0.0 @@ -2759,10 +2943,12 @@ export const getEquivalence: ( * Performs a side-effect for each element of the `Iterable`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3 + * ``` * * @since 2.0.0 */ @@ -2776,11 +2962,13 @@ export const forEach: { * preserving the order of the first occurrence of each element. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 2, 3, 3, 3] * const unique = Array.dedupeWith(numbers, (a, b) => a === b) * assert.deepStrictEqual(unique, [1, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -2823,11 +3011,13 @@ export const dedupe = | NonEmptyReadonlyArray>( * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 1, 2, 2, 3, 3] * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b) * assert.deepStrictEqual(unique, [1, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -2850,11 +3040,13 @@ export const dedupeAdjacentWith: { * Deduplicates adjacent elements that are identical. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 1, 2, 2, 3, 3] * const unique = Array.dedupeAdjacent(numbers) * assert.deepStrictEqual(unique, [1, 2, 3]) + * ``` * * @since 2.0.0 */ @@ -2864,11 +3056,13 @@ export const dedupeAdjacent: (self: Iterable) => Array = dedupeAdjacent * Joins the elements together with "sep" in the middle. * * @example + * ```ts * import { Array } from "effect" * * const strings = ["a", "b", "c"] * const joined = Array.join(strings, "-") * assert.deepStrictEqual(joined, "a-b-c") + * ``` * * @since 2.0.0 * @category folding @@ -2882,11 +3076,13 @@ export const join: { * Statefully maps over the chunk, producing new elements of type `B`. * * @example + * ```ts * import { Array } from "effect" * * const numbers = [1, 2, 3] * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n]) * assert.deepStrictEqual(result, [6, [1, 3, 6]]) + * ``` * * @since 2.0.0 * @category folding @@ -2921,12 +3117,14 @@ export const mapAccum: { * Zips this chunk crosswise with the specified chunk using the specified combiner. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2] * const array2 = ["a", "b"] * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`) * assert.deepStrictEqual(product, ["1-a", "1-b", "2-a", "2-b"]) + * ``` * * @since 2.0.0 * @category elements @@ -2944,12 +3142,14 @@ export const cartesianWith: { * Zips this chunk crosswise with the specified chunk. * * @example + * ```ts * import { Array } from "effect" * * const array1 = [1, 2] * const array2 = ["a", "b"] * const product = Array.cartesian(array1, array2) * assert.deepStrictEqual(product, [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]) + * ``` * * @since 2.0.0 * @category elements @@ -2985,6 +3185,7 @@ export const cartesian: { * @see {@link let_ let} * * @example + * ```ts * import { Array as Arr, pipe } from "effect" * const doResult = pipe( * Arr.Do, @@ -3005,6 +3206,7 @@ export const cartesian: { * if(_x < _y) result.push([_x, _y] as const) * } * } + * ``` * * @category do notation * @since 3.2.0 @@ -3030,6 +3232,7 @@ export const Do: ReadonlyArray<{}> = of({}) * @see {@link let_ let} * * @example + * ```ts * import { Array as Arr, pipe } from "effect" * const doResult = pipe( * Arr.Do, @@ -3050,6 +3253,7 @@ export const Do: ReadonlyArray<{}> = of({}) * if(_x < _y) result.push([_x, _y] as const) * } * } + * ``` * * @category do notation * @since 3.2.0 @@ -3087,6 +3291,7 @@ export const bind: { * @see {@link let_ let} * * @example + * ```ts * import { Array as Arr, pipe } from "effect" * const doResult = pipe( * Arr.Do, @@ -3107,6 +3312,7 @@ export const bind: { * if(_x < _y) result.push([_x, _y] as const) * } * } + * ``` * * @category do notation * @since 3.2.0 @@ -3148,6 +3354,7 @@ export { * @see {@link Do} * * @example + * ```ts * import { Array as Arr, pipe } from "effect" * const doResult = pipe( * Arr.Do, @@ -3169,6 +3376,7 @@ export { * } * } * + * ``` * @category do notation * @since 3.2.0 */ diff --git a/packages/effect/src/BigDecimal.ts b/packages/effect/src/BigDecimal.ts index 360dd6de230..72347aed704 100644 --- a/packages/effect/src/BigDecimal.ts +++ b/packages/effect/src/BigDecimal.ts @@ -134,10 +134,12 @@ const zero = unsafeMakeNormalized(bigint0, 0) * @param self - The `BigDecimal` to normalize. * * @example + * ```ts * import { normalize, make, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(normalize(unsafeFromString("123.00000")), normalize(make(123n, 0))) * assert.deepStrictEqual(normalize(unsafeFromString("12300000")), normalize(make(123n, -5))) + * ``` * * @since 2.0.0 * @category scaling @@ -205,9 +207,11 @@ export const scale: { * @param that - The second operand. * * @example + * ```ts * import { sum, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(sum(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("5")) + * ``` * * @since 2.0.0 * @category math @@ -242,9 +246,11 @@ export const sum: { * @param that - The second operand. * * @example + * ```ts * import { multiply, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(multiply(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("6")) + * ``` * * @since 2.0.0 * @category math @@ -267,9 +273,11 @@ export const multiply: { * @param that - The second operand. * * @example + * ```ts * import { subtract, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(subtract(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("-1")) + * ``` * * @since 2.0.0 * @category math @@ -377,11 +385,13 @@ export const roundTerminal = (n: bigint): bigint => { * @param that - The divisor operand. * * @example + * ```ts * import { BigDecimal, Option } from "effect" * * assert.deepStrictEqual(BigDecimal.divide(BigDecimal.unsafeFromString("6"), BigDecimal.unsafeFromString("3")), Option.some(BigDecimal.unsafeFromString("2"))) * assert.deepStrictEqual(BigDecimal.divide(BigDecimal.unsafeFromString("6"), BigDecimal.unsafeFromString("4")), Option.some(BigDecimal.unsafeFromString("1.5"))) * assert.deepStrictEqual(BigDecimal.divide(BigDecimal.unsafeFromString("6"), BigDecimal.unsafeFromString("0")), Option.none()) + * ``` * * @since 2.0.0 * @category math @@ -418,10 +428,12 @@ export const divide: { * @param that - The divisor operand.as * * @example + * ```ts * import { unsafeDivide, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(unsafeDivide(unsafeFromString("6"), unsafeFromString("3")), unsafeFromString("2")) * assert.deepStrictEqual(unsafeDivide(unsafeFromString("6"), unsafeFromString("4")), unsafeFromString("1.5")) + * ``` * * @since 2.0.0 * @category math @@ -473,11 +485,13 @@ export const Order: order.Order = order.make((self, that) => { * @param that - The second argument. * * @example + * ```ts * import { lessThan, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(lessThan(unsafeFromString("2"), unsafeFromString("3")), true) * assert.deepStrictEqual(lessThan(unsafeFromString("3"), unsafeFromString("3")), false) * assert.deepStrictEqual(lessThan(unsafeFromString("4"), unsafeFromString("3")), false) + * ``` * * @since 2.0.0 * @category predicates @@ -494,11 +508,13 @@ export const lessThan: { * @param that - The second `BigDecimal` to compare with. * * @example + * ```ts * import { lessThanOrEqualTo, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("2"), unsafeFromString("3")), true) * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("3"), unsafeFromString("3")), true) * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("4"), unsafeFromString("3")), false) + * ``` * * @since 2.0.0 * @category predicates @@ -515,11 +531,13 @@ export const lessThanOrEqualTo: { * @param that - The second argument. * * @example + * ```ts * import { greaterThan, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(greaterThan(unsafeFromString("2"), unsafeFromString("3")), false) * assert.deepStrictEqual(greaterThan(unsafeFromString("3"), unsafeFromString("3")), false) * assert.deepStrictEqual(greaterThan(unsafeFromString("4"), unsafeFromString("3")), true) + * ``` * * @since 2.0.0 * @category predicates @@ -536,11 +554,13 @@ export const greaterThan: { * @param that - The second `BigDecimal` to compare with. * * @example + * ```ts * import { greaterThanOrEqualTo, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("2"), unsafeFromString("3")), false) * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("3"), unsafeFromString("3")), true) * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("4"), unsafeFromString("3")), true) + * ``` * * @since 2.0.0 * @category predicates @@ -558,6 +578,7 @@ export const greaterThanOrEqualTo: { * @param maximum - The `maximum` value to check. * * @example + * ```ts * import { BigDecimal } from "effect" * * const between = BigDecimal.between({ @@ -568,6 +589,7 @@ export const greaterThanOrEqualTo: { * assert.deepStrictEqual(between(BigDecimal.unsafeFromString("3")), true) * assert.deepStrictEqual(between(BigDecimal.unsafeFromString("0")), false) * assert.deepStrictEqual(between(BigDecimal.unsafeFromString("6")), false) + * ``` * * @since 2.0.0 * @category predicates @@ -595,6 +617,7 @@ export const between: { * @param maximum - The upper end of the range. * * @example + * ```ts * import { BigDecimal } from "effect" * * const clamp = BigDecimal.clamp({ @@ -605,6 +628,7 @@ export const between: { * assert.deepStrictEqual(clamp(BigDecimal.unsafeFromString("3")), BigDecimal.unsafeFromString("3")) * assert.deepStrictEqual(clamp(BigDecimal.unsafeFromString("0")), BigDecimal.unsafeFromString("1")) * assert.deepStrictEqual(clamp(BigDecimal.unsafeFromString("6")), BigDecimal.unsafeFromString("5")) + * ``` * * @since 2.0.0 * @category math @@ -627,9 +651,11 @@ export const clamp: { * @param that - The second `BigDecimal`. * * @example + * ```ts * import { min, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(min(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("2")) + * ``` * * @since 2.0.0 * @category math @@ -646,9 +672,11 @@ export const min: { * @param that - The second `BigDecimal`. * * @example + * ```ts * import { max, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(max(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("3")) + * ``` * * @since 2.0.0 * @category math @@ -664,11 +692,13 @@ export const max: { * @param n - The `BigDecimal` to determine the sign of. * * @example + * ```ts * import { sign, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(sign(unsafeFromString("-5")), -1) * assert.deepStrictEqual(sign(unsafeFromString("0")), 0) * assert.deepStrictEqual(sign(unsafeFromString("5")), 1) + * ``` * * @since 2.0.0 * @category math @@ -681,11 +711,13 @@ export const sign = (n: BigDecimal): Ordering => n.value === bigint0 ? 0 : n.val * @param n - The `BigDecimal` to determine the absolute value of. * * @example + * ```ts * import { abs, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(abs(unsafeFromString("-5")), unsafeFromString("5")) * assert.deepStrictEqual(abs(unsafeFromString("0")), unsafeFromString("0")) * assert.deepStrictEqual(abs(unsafeFromString("5")), unsafeFromString("5")) + * ``` * * @since 2.0.0 * @category math @@ -698,10 +730,12 @@ export const abs = (n: BigDecimal): BigDecimal => n.value < bigint0 ? make(-n.va * @param n - The `BigDecimal` to negate. * * @example + * ```ts * import { negate, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(negate(unsafeFromString("3")), unsafeFromString("-3")) * assert.deepStrictEqual(negate(unsafeFromString("-6")), unsafeFromString("6")) + * ``` * * @since 2.0.0 * @category math @@ -717,11 +751,13 @@ export const negate = (n: BigDecimal): BigDecimal => make(-n.value, n.scale) * @param divisor - The divisor. * * @example + * ```ts * import { BigDecimal, Option } from "effect" * * assert.deepStrictEqual(BigDecimal.remainder(BigDecimal.unsafeFromString("2"), BigDecimal.unsafeFromString("2")), Option.some(BigDecimal.unsafeFromString("0"))) * assert.deepStrictEqual(BigDecimal.remainder(BigDecimal.unsafeFromString("3"), BigDecimal.unsafeFromString("2")), Option.some(BigDecimal.unsafeFromString("1"))) * assert.deepStrictEqual(BigDecimal.remainder(BigDecimal.unsafeFromString("-4"), BigDecimal.unsafeFromString("2")), Option.some(BigDecimal.unsafeFromString("0"))) + * ``` * * @since 2.0.0 * @category math @@ -747,11 +783,13 @@ export const remainder: { * @param divisor - The divisor. * * @example + * ```ts * import { unsafeRemainder, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("2"), unsafeFromString("2")), unsafeFromString("0")) * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("3"), unsafeFromString("2")), unsafeFromString("1")) * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("-4"), unsafeFromString("2")), unsafeFromString("0")) + * ``` * * @since 2.0.0 * @category math @@ -814,10 +852,12 @@ export const fromBigInt = (n: bigint): BigDecimal => make(n, 0) * @param value - The `number` value to create a `BigDecimal` from. * * @example + * ```ts * import { fromNumber, make } from "effect/BigDecimal" * * assert.deepStrictEqual(fromNumber(123), make(123n, 0)) * assert.deepStrictEqual(fromNumber(123.456), make(123456n, 3)) + * ``` * * @since 2.0.0 * @category constructors @@ -833,11 +873,13 @@ export const fromNumber = (n: number): BigDecimal => { * @param s - The `string` to parse. * * @example + * ```ts * import { BigDecimal, Option } from "effect" * * assert.deepStrictEqual(BigDecimal.fromString("123"), Option.some(BigDecimal.make(123n, 0))) * assert.deepStrictEqual(BigDecimal.fromString("123.456"), Option.some(BigDecimal.make(123456n, 3))) * assert.deepStrictEqual(BigDecimal.fromString("123.abc"), Option.none()) + * ``` * * @since 2.0.0 * @category constructors @@ -875,11 +917,13 @@ export const fromString = (s: string): Option.Option => { * @param s - The `string` to parse. * * @example + * ```ts * import { unsafeFromString, make } from "effect/BigDecimal" * * assert.deepStrictEqual(unsafeFromString("123"), make(123n, 0)) * assert.deepStrictEqual(unsafeFromString("123.456"), make(123456n, 3)) * assert.throws(() => unsafeFromString("123.abc")) + * ``` * * @since 2.0.0 * @category constructors @@ -893,11 +937,13 @@ export const unsafeFromString = (s: string): BigDecimal => * @param normalized - The `BigDecimal` to format. * * @example + * ```ts * import { format, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(format(unsafeFromString("-5")), "-5") * assert.deepStrictEqual(format(unsafeFromString("123.456")), "123.456") * assert.deepStrictEqual(format(unsafeFromString("-0.00000123")), "-0.00000123") + * ``` * * @since 2.0.0 * @category conversions @@ -936,9 +982,11 @@ export const format = (n: BigDecimal): string => { * @param n - The `BigDecimal` to convert. * * @example + * ```ts * import { unsafeToNumber, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(unsafeToNumber(unsafeFromString("123.456")), 123.456) + * ``` * * @since 2.0.0 * @category conversions @@ -951,11 +999,13 @@ export const unsafeToNumber = (n: BigDecimal): number => Number(format(n)) * @param n - The `BigDecimal` to check. * * @example + * ```ts * import { isInteger, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(isInteger(unsafeFromString("0")), true) * assert.deepStrictEqual(isInteger(unsafeFromString("1")), true) * assert.deepStrictEqual(isInteger(unsafeFromString("1.1")), false) + * ``` * * @since 2.0.0 * @category predicates @@ -968,10 +1018,12 @@ export const isInteger = (n: BigDecimal): boolean => normalize(n).scale <= 0 * @param n - The `BigDecimal` to check. * * @example + * ```ts * import { isZero, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(isZero(unsafeFromString("0")), true) * assert.deepStrictEqual(isZero(unsafeFromString("1")), false) + * ``` * * @since 2.0.0 * @category predicates @@ -984,11 +1036,13 @@ export const isZero = (n: BigDecimal): boolean => n.value === bigint0 * @param n - The `BigDecimal` to check. * * @example + * ```ts * import { isNegative, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(isNegative(unsafeFromString("-1")), true) * assert.deepStrictEqual(isNegative(unsafeFromString("0")), false) * assert.deepStrictEqual(isNegative(unsafeFromString("1")), false) + * ``` * * @since 2.0.0 * @category predicates @@ -1001,11 +1055,13 @@ export const isNegative = (n: BigDecimal): boolean => n.value < bigint0 * @param n - The `BigDecimal` to check. * * @example + * ```ts * import { isPositive, unsafeFromString } from "effect/BigDecimal" * * assert.deepStrictEqual(isPositive(unsafeFromString("-1")), false) * assert.deepStrictEqual(isPositive(unsafeFromString("0")), false) * assert.deepStrictEqual(isPositive(unsafeFromString("1")), true) + * ``` * * @since 2.0.0 * @category predicates diff --git a/packages/effect/src/BigInt.ts b/packages/effect/src/BigInt.ts index 6b6ea3d2bb4..f0b82e02705 100644 --- a/packages/effect/src/BigInt.ts +++ b/packages/effect/src/BigInt.ts @@ -23,10 +23,12 @@ const bigint2 = BigInt(2) * @param input - The value to test. * * @example + * ```ts * import { isBigInt } from "effect/BigInt" * * assert.deepStrictEqual(isBigInt(1n), true) * assert.deepStrictEqual(isBigInt(1), false) + * ``` * * @category guards * @since 2.0.0 @@ -40,9 +42,11 @@ export const isBigInt: (u: unknown) => u is bigint = predicate.isBigInt * @param that - The second operand. * * @example + * ```ts * import { sum } from "effect/BigInt" * * assert.deepStrictEqual(sum(2n, 3n), 5n) + * ``` * * @category math * @since 2.0.0 @@ -59,9 +63,11 @@ export const sum: { * @param that - The second operand. * * @example + * ```ts * import { multiply } from "effect/BigInt" * * assert.deepStrictEqual(multiply(2n, 3n), 6n) + * ``` * * @category math * @since 2.0.0 @@ -78,9 +84,11 @@ export const multiply: { * @param that - The second operand. * * @example + * ```ts * import { subtract } from "effect/BigInt" * * assert.deepStrictEqual(subtract(2n, 3n), -1n) + * ``` * * @category math * @since 2.0.0 @@ -102,10 +110,12 @@ export const subtract: { * @param that - The divisor operand. * * @example + * ```ts * import { BigInt, Option } from "effect" * * assert.deepStrictEqual(BigInt.divide(6n, 3n), Option.some(2n)) * assert.deepStrictEqual(BigInt.divide(6n, 0n), Option.none()) + * ``` * * @category math * @since 2.0.0 @@ -130,10 +140,12 @@ export const divide: { * @param that - The divisor operand. * * @example + * ```ts * import { unsafeDivide } from "effect/BigInt" * * assert.deepStrictEqual(unsafeDivide(6n, 3n), 2n) * assert.deepStrictEqual(unsafeDivide(6n, 4n), 1n) + * ``` * * @category math * @since 2.0.0 @@ -149,9 +161,11 @@ export const unsafeDivide: { * @param n - A `bigint` to be incremented. * * @example + * ```ts * import { increment } from "effect/BigInt" * * assert.deepStrictEqual(increment(2n), 3n) + * ``` * * @category math * @since 2.0.0 @@ -164,9 +178,11 @@ export const increment = (n: bigint): bigint => n + bigint1 * @param n - A `bigint` to be decremented. * * @example + * ```ts * import { decrement } from "effect/BigInt" * * assert.deepStrictEqual(decrement(3n), 2n) + * ``` * * @category math * @since 2.0.0 @@ -192,11 +208,13 @@ export const Order: order.Order = order.bigint * @param that - The second argument. * * @example + * ```ts * import { lessThan } from "effect/BigInt" * * assert.deepStrictEqual(lessThan(2n, 3n), true) * assert.deepStrictEqual(lessThan(3n, 3n), false) * assert.deepStrictEqual(lessThan(4n, 3n), false) + * ``` * * @category predicates * @since 2.0.0 @@ -213,11 +231,13 @@ export const lessThan: { * @param that - The second `bigint` to compare with. * * @example + * ```ts * import { lessThanOrEqualTo } from "effect/BigInt" * * assert.deepStrictEqual(lessThanOrEqualTo(2n, 3n), true) * assert.deepStrictEqual(lessThanOrEqualTo(3n, 3n), true) * assert.deepStrictEqual(lessThanOrEqualTo(4n, 3n), false) + * ``` * * @category predicates * @since 2.0.0 @@ -234,11 +254,13 @@ export const lessThanOrEqualTo: { * @param that - The second argument. * * @example + * ```ts * import { greaterThan } from "effect/BigInt" * * assert.deepStrictEqual(greaterThan(2n, 3n), false) * assert.deepStrictEqual(greaterThan(3n, 3n), false) * assert.deepStrictEqual(greaterThan(4n, 3n), true) + * ``` * * @category predicates * @since 2.0.0 @@ -255,11 +277,13 @@ export const greaterThan: { * @param that - The second `bigint` to compare with. * * @example + * ```ts * import { greaterThanOrEqualTo } from "effect/BigInt" * * assert.deepStrictEqual(greaterThanOrEqualTo(2n, 3n), false) * assert.deepStrictEqual(greaterThanOrEqualTo(3n, 3n), true) * assert.deepStrictEqual(greaterThanOrEqualTo(4n, 3n), true) + * ``` * * @category predicates * @since 2.0.0 @@ -277,6 +301,7 @@ export const greaterThanOrEqualTo: { * @param maximum - The `maximum` value to check. * * @example + * ```ts * import { BigInt } from "effect" * * const between = BigInt.between({ minimum: 0n, maximum: 5n }) @@ -284,6 +309,7 @@ export const greaterThanOrEqualTo: { * assert.deepStrictEqual(between(3n), true) * assert.deepStrictEqual(between(-1n), false) * assert.deepStrictEqual(between(6n), false) + * ``` * * @category predicates * @since 2.0.0 @@ -311,6 +337,7 @@ export const between: { * @param maximum - The upper end of the range. * * @example + * ```ts * import { BigInt } from "effect" * * const clamp = BigInt.clamp({ minimum: 1n, maximum: 5n }) @@ -318,6 +345,7 @@ export const between: { * assert.equal(clamp(3n), 3n) * assert.equal(clamp(0n), 1n) * assert.equal(clamp(6n), 5n) + * ``` * * @since 2.0.0 */ @@ -339,9 +367,11 @@ export const clamp: { * @param that - The second `bigint`. * * @example + * ```ts * import { min } from "effect/BigInt" * * assert.deepStrictEqual(min(2n, 3n), 2n) + * ``` * * @since 2.0.0 */ @@ -357,9 +387,11 @@ export const min: { * @param that - The second `bigint`. * * @example + * ```ts * import { max } from "effect/BigInt" * * assert.deepStrictEqual(max(2n, 3n), 3n) + * ``` * * @since 2.0.0 */ @@ -374,11 +406,13 @@ export const max: { * @param n - The `bigint` to determine the sign of. * * @example + * ```ts * import { sign } from "effect/BigInt" * * assert.deepStrictEqual(sign(-5n), -1) * assert.deepStrictEqual(sign(0n), 0) * assert.deepStrictEqual(sign(5n), 1) + * ``` * * @category math * @since 2.0.0 @@ -391,11 +425,13 @@ export const sign = (n: bigint): Ordering => Order(n, bigint0) * @param n - The `bigint` to determine the absolute value of. * * @example + * ```ts * import { abs } from "effect/BigInt" * * assert.deepStrictEqual(abs(-5n), 5n) * assert.deepStrictEqual(abs(0n), 0n) * assert.deepStrictEqual(abs(5n), 5n) + * ``` * * @category math * @since 2.0.0 @@ -409,11 +445,13 @@ export const abs = (n: bigint): bigint => (n < bigint0 ? -n : n) * @param b - The second `bigint`. * * @example + * ```ts * import { gcd } from "effect/BigInt" * * assert.deepStrictEqual(gcd(2n, 3n), 1n) * assert.deepStrictEqual(gcd(2n, 4n), 2n) * assert.deepStrictEqual(gcd(16n, 24n), 8n) + * ``` * * @category math * @since 2.0.0 @@ -437,11 +475,13 @@ export const gcd: { * @param b - The second `bigint`. * * @example + * ```ts * import { lcm } from "effect/BigInt" * * assert.deepStrictEqual(lcm(2n, 3n), 6n) * assert.deepStrictEqual(lcm(2n, 4n), 4n) * assert.deepStrictEqual(lcm(16n, 24n), 48n) + * ``` * * @category math * @since 2.0.0 @@ -457,11 +497,13 @@ export const lcm: { * @param n - The `bigint` to determine the square root of. * * @example + * ```ts * import { unsafeSqrt } from "effect/BigInt" * * assert.deepStrictEqual(unsafeSqrt(4n), 2n) * assert.deepStrictEqual(unsafeSqrt(9n), 3n) * assert.deepStrictEqual(unsafeSqrt(16n), 4n) + * ``` * * @category math * @since 2.0.0 @@ -486,12 +528,14 @@ export const unsafeSqrt = (n: bigint): bigint => { * @param n - The `bigint` to determine the square root of. * * @example + * ```ts * import { BigInt, Option } from "effect" * * assert.deepStrictEqual(BigInt.sqrt(4n), Option.some(2n)) * assert.deepStrictEqual(BigInt.sqrt(9n), Option.some(3n)) * assert.deepStrictEqual(BigInt.sqrt(16n), Option.some(4n)) * assert.deepStrictEqual(BigInt.sqrt(-1n), Option.none()) + * ``` * * @category math * @since 2.0.0 @@ -505,9 +549,11 @@ export const sqrt = (n: bigint): Option.Option => * @param collection - The collection of `bigint`s to sum. * * @example + * ```ts * import { sumAll } from "effect/BigInt" * * assert.deepStrictEqual(sumAll([2n, 3n, 4n]), 9n) + * ``` * * @category math * @since 2.0.0 @@ -526,9 +572,11 @@ export const sumAll = (collection: Iterable): bigint => { * @param collection - The collection of `bigint`s to multiply. * * @example + * ```ts * import { multiplyAll } from "effect/BigInt" * * assert.deepStrictEqual(multiplyAll([2n, 3n, 4n]), 24n) + * ``` * * @category math * @since 2.0.0 @@ -554,11 +602,13 @@ export const multiplyAll = (collection: Iterable): bigint => { * @param b - The `bigint` to be converted to a `number`. * * @example + * ```ts * import { BigInt as BI, Option } from "effect" * * assert.deepStrictEqual(BI.toNumber(BigInt(42)), Option.some(42)) * assert.deepStrictEqual(BI.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1)), Option.none()) * assert.deepStrictEqual(BI.toNumber(BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1)), Option.none()) + * ``` * * @category conversions * @since 2.0.0 @@ -579,11 +629,13 @@ export const toNumber = (b: bigint): Option.Option => { * @param s - The string to be converted to a `bigint`. * * @example + * ```ts * import { BigInt as BI, Option } from "effect" * * assert.deepStrictEqual(BI.fromString("42"), Option.some(BigInt(42))) * assert.deepStrictEqual(BI.fromString(" "), Option.none()) * assert.deepStrictEqual(BI.fromString("a"), Option.none()) + * ``` * * @category conversions * @since 2.4.12 @@ -608,11 +660,13 @@ export const fromString = (s: string): Option.Option => { * @param n - The number to be converted to a `bigint`. * * @example + * ```ts * import { BigInt as BI, Option } from "effect" * * assert.deepStrictEqual(BI.fromNumber(42), Option.some(BigInt(42))) * assert.deepStrictEqual(BI.fromNumber(Number.MAX_SAFE_INTEGER + 1), Option.none()) * assert.deepStrictEqual(BI.fromNumber(Number.MIN_SAFE_INTEGER - 1), Option.none()) + * ``` * * @category conversions * @since 2.4.12 diff --git a/packages/effect/src/Boolean.ts b/packages/effect/src/Boolean.ts index 5b26c8ef445..f15df71367c 100644 --- a/packages/effect/src/Boolean.ts +++ b/packages/effect/src/Boolean.ts @@ -17,10 +17,12 @@ import * as predicate from "./Predicate.js" * @param input - The value to test. * * @example + * ```ts * import { isBoolean } from "effect/Boolean" * * assert.deepStrictEqual(isBoolean(true), true) * assert.deepStrictEqual(isBoolean("true"), false) + * ``` * * @category guards * @since 2.0.0 @@ -36,9 +38,11 @@ export const isBoolean: (input: unknown) => input is boolean = predicate.isBoole * @param onTrue - a lazy evaluation function that will be executed when the `value` is `true`. * * @example + * ```ts * import { Boolean } from "effect" * * assert.deepStrictEqual(Boolean.match(true, { onFalse: () => "It's false!", onTrue: () => "It's true!" }), "It's true!") + * ``` * * @category pattern matching * @since 2.0.0 @@ -73,10 +77,12 @@ export const Order: order.Order = order.boolean * Negates the given boolean: `!self` * * @example + * ```ts * import { not } from "effect/Boolean" * * assert.deepStrictEqual(not(true), false) * assert.deepStrictEqual(not(false), true) + * ``` * * @category combinators * @since 2.0.0 @@ -87,12 +93,14 @@ export const not = (self: boolean): boolean => !self * Combines two boolean using AND: `self && that`. * * @example + * ```ts * import { and } from "effect/Boolean" * * assert.deepStrictEqual(and(true, true), true) * assert.deepStrictEqual(and(true, false), false) * assert.deepStrictEqual(and(false, true), false) * assert.deepStrictEqual(and(false, false), false) + * ``` * * @category combinators * @since 2.0.0 @@ -106,12 +114,14 @@ export const and: { * Combines two boolean using NAND: `!(self && that)`. * * @example + * ```ts * import { nand } from "effect/Boolean" * * assert.deepStrictEqual(nand(true, true), false) * assert.deepStrictEqual(nand(true, false), true) * assert.deepStrictEqual(nand(false, true), true) * assert.deepStrictEqual(nand(false, false), true) + * ``` * * @category combinators * @since 2.0.0 @@ -125,12 +135,14 @@ export const nand: { * Combines two boolean using OR: `self || that`. * * @example + * ```ts * import { or } from "effect/Boolean" * * assert.deepStrictEqual(or(true, true), true) * assert.deepStrictEqual(or(true, false), true) * assert.deepStrictEqual(or(false, true), true) * assert.deepStrictEqual(or(false, false), false) + * ``` * * @category combinators * @since 2.0.0 @@ -144,12 +156,14 @@ export const or: { * Combines two booleans using NOR: `!(self || that)`. * * @example + * ```ts * import { nor } from "effect/Boolean" * * assert.deepStrictEqual(nor(true, true), false) * assert.deepStrictEqual(nor(true, false), false) * assert.deepStrictEqual(nor(false, true), false) * assert.deepStrictEqual(nor(false, false), true) + * ``` * * @category combinators * @since 2.0.0 @@ -163,12 +177,14 @@ export const nor: { * Combines two booleans using XOR: `(!self && that) || (self && !that)`. * * @example + * ```ts * import { xor } from "effect/Boolean" * * assert.deepStrictEqual(xor(true, true), false) * assert.deepStrictEqual(xor(true, false), true) * assert.deepStrictEqual(xor(false, true), true) * assert.deepStrictEqual(xor(false, false), false) + * ``` * * @category combinators * @since 2.0.0 @@ -182,12 +198,14 @@ export const xor: { * Combines two booleans using EQV (aka XNOR): `!xor(self, that)`. * * @example + * ```ts * import { eqv } from "effect/Boolean" * * assert.deepStrictEqual(eqv(true, true), true) * assert.deepStrictEqual(eqv(true, false), false) * assert.deepStrictEqual(eqv(false, true), false) * assert.deepStrictEqual(eqv(false, false), true) + * ``` * * @category combinators * @since 2.0.0 @@ -201,12 +219,14 @@ export const eqv: { * Combines two booleans using an implication: `(!self || that)`. * * @example + * ```ts * import { implies } from "effect/Boolean" * * assert.deepStrictEqual(implies(true, true), true) * assert.deepStrictEqual(implies(true, false), false) * assert.deepStrictEqual(implies(false, true), true) * assert.deepStrictEqual(implies(false, false), true) + * ``` * * @category combinators * @since 2.0.0 @@ -222,10 +242,12 @@ export const implies: { * @param collection - An iterable collection of booleans. * * @example + * ```ts * import { every } from "effect/Boolean" * * assert.deepStrictEqual(every([true, true, true]), true) * assert.deepStrictEqual(every([true, false, true]), false) + * ``` * * @since 2.0.0 */ @@ -244,10 +266,12 @@ export const every = (collection: Iterable): boolean => { * @param collection - An iterable collection of booleans. * * @example + * ```ts * import { some } from "effect/Boolean" * * assert.deepStrictEqual(some([true, false, true]), true) * assert.deepStrictEqual(some([false, false, false]), false) + * ``` * * @since 2.0.0 */ diff --git a/packages/effect/src/Brand.ts b/packages/effect/src/Brand.ts index 48925de65d3..d3569a46916 100644 --- a/packages/effect/src/Brand.ts +++ b/packages/effect/src/Brand.ts @@ -196,6 +196,7 @@ export const errors: (...errors: Array) => Brand.BrandErrors * @param onFailure - Takes the unbranded value that did not pass the `refinement` predicate and returns a `BrandErrors`. * * @example + * ```ts * import { Brand } from "effect" * * type Int = number & Brand.Brand<"Int"> @@ -207,6 +208,7 @@ export const errors: (...errors: Array) => Brand.BrandErrors * * assert.strictEqual(Int(1), 1) * assert.throws(() => Int(1.1)) + * ``` * * @since 2.0.0 * @category constructors @@ -247,6 +249,7 @@ export function refined>( * If you also want to perform some validation, see {@link refined}. * * @example + * ```ts * import { Brand } from "effect" * * type UserId = number & Brand.Brand<"UserId"> @@ -254,6 +257,7 @@ export function refined>( * const UserId = Brand.nominal() * * assert.strictEqual(UserId(1), 1) + * ``` * * @since 2.0.0 * @category constructors @@ -275,6 +279,7 @@ export const nominal = >(): Brand.Constructor< * This API is useful when you want to validate that the input data passes multiple brand validators. * * @example + * ```ts * import { Brand } from "effect" * * type Int = number & Brand.Brand<"Int"> @@ -292,6 +297,7 @@ export const nominal = >(): Brand.Constructor< * * assert.strictEqual(PositiveInt(1), 1) * assert.throws(() => PositiveInt(1.1)) + * ``` * * @since 2.0.0 * @category combining diff --git a/packages/effect/src/Chunk.ts b/packages/effect/src/Chunk.ts index ab7ddffab32..60ac5f071e5 100644 --- a/packages/effect/src/Chunk.ts +++ b/packages/effect/src/Chunk.ts @@ -350,11 +350,13 @@ const reverseChunk = (self: Chunk): Chunk => { * Importantly, if the input chunk is a `NonEmptyChunk`, the reversed chunk will also be a `NonEmptyChunk`. * * @example + * ```ts * import { Chunk } from "effect" * * const numbers = Chunk.make(1, 2, 3) * const reversedNumbers = Chunk.reverse(numbers) * assert.deepStrictEqual(reversedNumbers, Chunk.make(3, 2, 1)) + * ``` * * @since 2.0.0 * @category elements @@ -576,12 +578,14 @@ export const dropWhile: { * If either chunk is non-empty, the result is also a non-empty chunk. * * @example + * ```ts * import { Chunk } from "effect" * * assert.deepStrictEqual( * Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make("a", "b")), Chunk.toArray), * ["a", "b", 1, 2] * ) + * ``` * * @category concatenating * @since 2.0.0 @@ -600,12 +604,14 @@ export const prependAll: { * If either chunk is non-empty, the result is also a non-empty chunk. * * @example + * ```ts * import { Chunk } from "effect" * * assert.deepStrictEqual( * Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make("a", "b")), Chunk.toArray), * [1, 2, "a", "b"] * ) + * ``` * * @category concatenating * @since 2.0.0 @@ -903,12 +909,14 @@ export declare namespace Chunk { * If the input chunk is non-empty, the resulting chunk will also be non-empty. * * @example + * ```ts * import { Chunk } from "effect" * * assert.deepStrictEqual( * Chunk.map(Chunk.make(1, 2), (n) => n + 1), * Chunk.make(2, 3) * ) + * ``` * * @since 2.0.0 * @category mapping diff --git a/packages/effect/src/Config.ts b/packages/effect/src/Config.ts index 04f82fcccd6..69bc2681808 100644 --- a/packages/effect/src/Config.ts +++ b/packages/effect/src/Config.ts @@ -172,9 +172,11 @@ export const integer: (name?: string) => Config = internal.integer * Constructs a config for a literal value. * * @example + * ```ts * import { Config } from "effect" * * const config = Config.literal("http", "https")("PROTOCOL") + * ``` * * @since 2.0.0 * @category constructors diff --git a/packages/effect/src/Context.ts b/packages/effect/src/Context.ts index b91ef354607..fb53b708097 100644 --- a/packages/effect/src/Context.ts +++ b/packages/effect/src/Context.ts @@ -101,9 +101,11 @@ export declare namespace Tag { * @param key - A key that will be used to compare tags. * * @example + * ```ts * import { Context } from "effect" * * assert.strictEqual(Context.GenericTag("PORT").key === Context.GenericTag("PORT").key, true) + * ``` * * @since 2.0.0 * @category constructors @@ -148,9 +150,11 @@ export const unsafeMake: (unsafeMap: Map) => Context input is Context = internal.i * @param input - The value to be checked if it is a `Tag`. * * @example + * ```ts * import { Context } from "effect" * * assert.strictEqual(Context.isTag(Context.GenericTag("Tag")), true) + * ``` * * @since 2.0.0 * @category guards @@ -176,9 +182,11 @@ export const isTag: (input: unknown) => input is Tag = internal.isTag * Returns an empty `Context`. * * @example + * ```ts * import { Context } from "effect" * * assert.strictEqual(Context.isContext(Context.empty()), true) + * ``` * * @since 2.0.0 * @category constructors @@ -189,6 +197,7 @@ export const empty: () => Context = internal.empty * Creates a new `Context` with a single service associated to the tag. * * @example + * ```ts * import { Context } from "effect" * * const Port = Context.GenericTag<{ PORT: number }>("Port") @@ -196,6 +205,7 @@ export const empty: () => Context = internal.empty * const Services = Context.make(Port, { PORT: 8080 }) * * assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 }) + * ``` * * @since 2.0.0 * @category constructors @@ -207,6 +217,7 @@ export const make: >(tag: T, service: Tag.Service) => * Adds a service to a given `Context`. * * @example + * ```ts * import { Context, pipe } from "effect" * * const Port = Context.GenericTag<{ PORT: number }>("Port") @@ -221,6 +232,7 @@ export const make: >(tag: T, service: Tag.Service) => * * assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 }) * assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 }) + * ``` * * @since 2.0.0 */ @@ -243,6 +255,7 @@ export const add: { * @param tag - The `Tag` of the service to retrieve. * * @example + * ```ts * import { pipe, Context } from "effect" * * const Port = Context.GenericTag<{ PORT: number }>("Port") @@ -254,6 +267,7 @@ export const add: { * ) * * assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 }) + * ``` * * @since 2.0.0 * @category getters @@ -285,6 +299,7 @@ export const getOrElse: { * @param tag - The `Tag` of the service to retrieve. * * @example + * ```ts * import { Context } from "effect" * * const Port = Context.GenericTag<{ PORT: number }>("Port") @@ -294,6 +309,7 @@ export const getOrElse: { * * assert.deepStrictEqual(Context.unsafeGet(Services, Port), { PORT: 8080 }) * assert.throws(() => Context.unsafeGet(Services, Timeout)) + * ``` * * @since 2.0.0 * @category unsafe @@ -311,6 +327,7 @@ export const unsafeGet: { * @param tag - The `Tag` of the service to retrieve. * * @example + * ```ts * import { Context, Option } from "effect" * * const Port = Context.GenericTag<{ PORT: number }>("Port") @@ -320,6 +337,7 @@ export const unsafeGet: { * * assert.deepStrictEqual(Context.getOption(Services, Port), Option.some({ PORT: 8080 })) * assert.deepStrictEqual(Context.getOption(Services, Timeout), Option.none()) + * ``` * * @since 2.0.0 * @category getters @@ -336,6 +354,7 @@ export const getOption: { * @param that - The second `Context` to merge. * * @example + * ```ts * import { Context } from "effect" * * const Port = Context.GenericTag<{ PORT: number }>("Port") @@ -348,6 +367,7 @@ export const getOption: { * * assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 }) * assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 }) + * ``` * * @since 2.0.0 */ @@ -363,6 +383,7 @@ export const merge: { * @param tags - The list of `Tag`s to be included in the new `Context`. * * @example + * ```ts * import { pipe, Context, Option } from "effect" * * const Port = Context.GenericTag<{ PORT: number }>("Port") @@ -377,6 +398,7 @@ export const merge: { * * assert.deepStrictEqual(Context.getOption(Services, Port), Option.some({ PORT: 8080 })) * assert.deepStrictEqual(Context.getOption(Services, Timeout), Option.none()) + * ``` * * @since 2.0.0 */ @@ -394,6 +416,7 @@ export const omit: >>( /** * @example + * ```ts * import { Context, Layer } from "effect" * * class MyTag extends Context.Tag("MyTag")< @@ -402,6 +425,7 @@ export const omit: >>( * >() { * static Live = Layer.succeed(this, { myNum: 108 }) * } + * ``` * * @since 2.0.0 * @category constructors diff --git a/packages/effect/src/Cron.ts b/packages/effect/src/Cron.ts index 856d6c0b443..83d67dc64aa 100644 --- a/packages/effect/src/Cron.ts +++ b/packages/effect/src/Cron.ts @@ -170,6 +170,7 @@ export const isParseError = (u: unknown): u is ParseError => hasProperty(u, Pars * @param cron - The cron expression to parse. * * @example + * ```ts * import { Cron, Either } from "effect" * * // At 04:00 on every day-of-month from 8 through 14. @@ -180,6 +181,7 @@ export const isParseError = (u: unknown): u is ParseError => hasProperty(u, Pars * months: [], * weekdays: [] * }))) + * ``` * * @since 2.0.0 * @category constructors @@ -207,11 +209,13 @@ export const parse = (cron: string): Either.Either => { * @param date - The `Date` to check against. * * @example + * ```ts * import { Cron, Either } from "effect" * * const cron = Either.getOrThrow(Cron.parse("0 4 8-14 * *")) * assert.deepStrictEqual(Cron.match(cron, new Date("2021-01-08 04:00:00")), true) * assert.deepStrictEqual(Cron.match(cron, new Date("2021-01-08 05:00:00")), false) + * ``` * * @since 2.0.0 */ @@ -256,11 +260,13 @@ export const match = (cron: Cron, date: Date): boolean => { * Uses the current time as a starting point if no value is provided for `now`. * * @example + * ```ts * import { Cron, Either } from "effect" * * const after = new Date("2021-01-01 00:00:00") * const cron = Either.getOrThrow(Cron.parse("0 4 8-14 * *")) * assert.deepStrictEqual(Cron.next(cron, after), new Date("2021-01-08 04:00:00")) + * ``` * * @param cron - The `Cron` instance. * @param now - The `Date` to start searching from. diff --git a/packages/effect/src/Data.ts b/packages/effect/src/Data.ts index 6b02cc2df75..1656e54ba89 100644 --- a/packages/effect/src/Data.ts +++ b/packages/effect/src/Data.ts @@ -27,6 +27,7 @@ export declare namespace Case { /** * @example + * ```ts * import { Data, Equal } from "effect" * * const alice = Data.struct({ name: "Alice", age: 30 }) @@ -38,6 +39,7 @@ export declare namespace Case { * * assert.deepStrictEqual(Equal.equals(alice, { name: "Alice", age: 30 }), false) * assert.deepStrictEqual(Equal.equals(alice, bob), false) + * ``` * * @category constructors * @since 2.0.0 @@ -53,6 +55,7 @@ export const unsafeStruct = >(as: A): { readonly [ /** * @example + * ```ts * import { Data, Equal } from "effect" * * const alice = Data.tuple("Alice", 30) @@ -64,6 +67,7 @@ export const unsafeStruct = >(as: A): { readonly [ * * assert.deepStrictEqual(Equal.equals(alice, ["Alice", 30]), false) * assert.deepStrictEqual(Equal.equals(alice, bob), false) + * ``` * * @category constructors * @since 2.0.0 @@ -72,6 +76,7 @@ export const tuple = >(...as: As): Readonly => /** * @example + * ```ts * import { Data, Equal } from "effect" * * const alice = Data.struct({ name: "Alice", age: 30 }) @@ -89,6 +94,7 @@ export const tuple = >(...as: As): Readonly => * ), * true * ) + * ``` * * @category constructors * @since 2.0.0 @@ -110,6 +116,7 @@ export { * Provides a constructor for the specified `Case`. * * @example + * ```ts * import { Data, Equal } from "effect" * * interface Person { @@ -128,6 +135,7 @@ export { * assert.deepStrictEqual(Equal.equals(mike1, mike2), true) * assert.deepStrictEqual(Equal.equals(mike1, john), false) * + * ``` * @since 2.0.0 * @category constructors */ @@ -138,6 +146,7 @@ export { * Provides a tagged constructor for the specified `Case`. * * @example + * ```ts * import { Data } from "effect" * * interface Person { @@ -150,6 +159,7 @@ export { * const mike = Person({ name: "Mike" }) * * assert.deepEqual(mike, { _tag: "Person", name: "Mike" }) + * ``` * * @since 2.0.0 * @category constructors @@ -167,6 +177,7 @@ export const tagged = ( * Provides a constructor for a Case Class. * * @example + * ```ts * import { Data, Equal } from "effect" * * class Person extends Data.Class<{ readonly name: string }> {} @@ -179,6 +190,7 @@ export const tagged = ( * // Checking equality * assert.deepStrictEqual(Equal.equals(mike1, mike2), true) * assert.deepStrictEqual(Equal.equals(mike1, john), false) + * ``` * * @since 2.0.0 * @category constructors @@ -192,6 +204,7 @@ export const Class: new = {}>( * Provides a Tagged constructor for a Case Class. * * @example + * ```ts * import { Data, Equal } from "effect" * * class Person extends Data.TaggedClass("Person")<{ readonly name: string }> {} @@ -206,6 +219,7 @@ export const Class: new = {}>( * assert.deepStrictEqual(Equal.equals(mike1, john), false) * * assert.deepStrictEqual(mike1._tag, "Person") + * ``` * * @since 2.0.0 * @category constructors @@ -403,6 +417,7 @@ export declare namespace TaggedEnum { * the constructor. * * @example + * ```ts * import { Data } from "effect" * * const { BadRequest, NotFound } = Data.taggedEnum< @@ -411,6 +426,7 @@ export declare namespace TaggedEnum { * >() * * const notFound = NotFound({ status: 404, message: "Not Found" }) + * ``` * * @example * import { Data } from "effect" diff --git a/packages/effect/src/DateTime.ts b/packages/effect/src/DateTime.ts index 4d847b2b7d8..89e8556d466 100644 --- a/packages/effect/src/DateTime.ts +++ b/packages/effect/src/DateTime.ts @@ -436,6 +436,7 @@ export const unsafeFromDate = (date: Date): Utc => { * @since 3.6.0 * @category constructors * @example + * ```ts * import { DateTime } from "effect" * * // from Date @@ -446,6 +447,7 @@ export const unsafeFromDate = (date: Date): Utc => { * * // from string * DateTime.unsafeMake("2024-01-01") + * ``` */ export const unsafeMake = (input: A): DateTime.PreserveZone => { if (isDateTime(input)) { @@ -470,9 +472,11 @@ export const unsafeMake = (input: A): DateTime.Preserv * @since 3.6.0 * @category constructors * @example + * ```ts * import { DateTime } from "effect" * * DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" }) + * ``` */ export const unsafeMakeZoned = (input: DateTime.Input, options?: { readonly timeZone?: number | string | TimeZone | undefined @@ -513,9 +517,11 @@ export const unsafeMakeZoned = (input: DateTime.Input, options?: { * @since 3.6.0 * @category constructors * @example + * ```ts * import { DateTime } from "effect" * * DateTime.makeZoned(new Date(), { timeZone: "Europe/London" }) + * ``` */ export const makeZoned: ( input: DateTime.Input, @@ -539,6 +545,7 @@ export const makeZoned: ( * @since 3.6.0 * @category constructors * @example + * ```ts * import { DateTime } from "effect" * * // from Date @@ -549,6 +556,7 @@ export const makeZoned: ( * * // from string * DateTime.make("2024-01-01") + * ``` */ export const make: (input: A) => Option.Option> = Option .liftThrowable(unsafeMake) @@ -579,11 +587,13 @@ export const makeZonedFromString = (input: string): Option.Option => { * @since 3.6.0 * @category constructors * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now * }) + * ``` */ export const now: Effect.Effect = Effect.map(Clock.currentTimeMillis, makeUtc) @@ -605,6 +615,7 @@ export const unsafeNow: LazyArg = () => makeUtc(Date.now()) * @since 3.6.0 * @category time zones * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -614,6 +625,7 @@ export const unsafeNow: LazyArg = () => makeUtc(Date.now()) * // set the time zone * const zoned: DateTime.Zoned = DateTime.setZone(now, zone) * }) + * ``` */ export const setZone: { (zone: TimeZone, options?: { @@ -637,6 +649,7 @@ export const setZone: { * @since 3.6.0 * @category time zones * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -645,6 +658,7 @@ export const setZone: { * // set the offset time zone in milliseconds * const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000) * }) + * ``` */ export const setZoneOffset: { (offset: number, options?: { @@ -773,6 +787,7 @@ export const zoneFromString = (zone: string): Option.Option => { * @since 3.6.0 * @category time zones * @example + * ```ts * import { DateTime, Effect } from "effect" * * // Outputs "+03:00" @@ -780,6 +795,7 @@ export const zoneFromString = (zone: string): Option.Option => { * * // Outputs "Europe/London" * DateTime.zoneToString(DateTime.zoneUnsafeMakeNamed("Europe/London")) + * ``` */ export const zoneToString = (self: TimeZone): string => { if (self._tag === "Offset") { @@ -795,6 +811,7 @@ export const zoneToString = (self: TimeZone): string => { * @since 3.6.0 * @category time zones * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -802,6 +819,7 @@ export const zoneToString = (self: TimeZone): string => { * // set the time zone, returns an Option * DateTime.setZoneNamed(now, "Europe/London") * }) + * ``` */ export const setZoneNamed: { (zoneId: string, options?: { @@ -824,6 +842,7 @@ export const setZoneNamed: { * @since 3.6.0 * @category time zones * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -831,6 +850,7 @@ export const setZoneNamed: { * // set the time zone * DateTime.unsafeSetZoneNamed(now, "Europe/London") * }) + * ``` */ export const unsafeSetZoneNamed: { (zoneId: string, options?: { @@ -856,6 +876,7 @@ export const unsafeSetZoneNamed: { * @since 3.6.0 * @category comparisons * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -865,6 +886,7 @@ export const unsafeSetZoneNamed: { * // returns 60000 * DateTime.distance(now, other) * }) + * ``` */ export const distance: { (other: DateTime): (self: DateTime) => number @@ -883,6 +905,7 @@ export const distance: { * @since 3.6.0 * @category comparisons * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -895,6 +918,7 @@ export const distance: { * // returns Either.left(Duration.minutes(1)) * DateTime.distanceDurationEither(other, now) * }) + * ``` */ export const distanceDurationEither: { (other: DateTime): (self: DateTime) => Either.Either @@ -912,6 +936,7 @@ export const distanceDurationEither: { * @since 3.6.0 * @category comparisons * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -921,6 +946,7 @@ export const distanceDurationEither: { * // returns Duration.minutes(1) * DateTime.distanceDuration(now, other) * }) + * ``` */ export const distanceDuration: { (other: DateTime): (self: DateTime) => Duration.Duration @@ -1103,6 +1129,7 @@ export const toEpochMillis = (self: DateTime): number => self.epochMillis * @since 3.6.0 * @category conversions * @example + * ```ts * import { DateTime } from "effect" * * // returns "2024-01-01T00:00:00Z" @@ -1113,6 +1140,7 @@ export const toEpochMillis = (self: DateTime): number => self.epochMillis * DateTime.removeTime, * DateTime.formatIso * ) + * ``` */ export const removeTime = (self: DateTime): Utc => withDate(self, (date) => { @@ -1177,11 +1205,13 @@ export const toPartsUtc = (self: DateTime): DateTime.PartsWithWeekday => { * @since 3.6.0 * @category parts * @example + * ```ts * import { DateTime } from "effect" * * const now = DateTime.unsafeMake({ year: 2024 }) * const year = DateTime.getPartUtc(now, "year") * assert.strictEqual(year, 2024) + * ``` */ export const getPartUtc: { (part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number @@ -1196,11 +1226,13 @@ export const getPartUtc: { * @since 3.6.0 * @category parts * @example + * ```ts * import { DateTime } from "effect" * * const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" }) * const year = DateTime.getPart(now, "year") * assert.strictEqual(year, 2024) + * ``` */ export const getPart: { (part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number @@ -1287,6 +1319,7 @@ export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZon * @since 3.6.0 * @category current time zone * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { @@ -1295,6 +1328,7 @@ export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZon * // set the time zone to "Europe/London" * const zoned = yield* DateTime.setZoneCurrent(now) * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) + * ``` */ export const setZoneCurrent = (self: DateTime): Effect.Effect => Effect.map(CurrentTimeZone, (zone) => setZone(self, zone)) @@ -1305,6 +1339,7 @@ export const setZoneCurrent = (self: DateTime): Effect.Effect(effect: Effect.Effect) => Effect.Effect> @@ -1329,12 +1365,14 @@ export const withCurrentZone: { * @since 3.6.0 * @category current time zone * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { * // will use the system's local time zone * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneLocal) + * ``` */ export const withCurrentZoneLocal = ( effect: Effect.Effect @@ -1347,12 +1385,14 @@ export const withCurrentZoneLocal = ( * @since 3.6.0 * @category current time zone * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { * // will use the system's local time zone * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000)) + * ``` */ export const withCurrentZoneOffset: { (offset: number): ( @@ -1374,12 +1414,14 @@ export const withCurrentZoneOffset: { * @since 3.6.0 * @category current time zone * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { * // will use the "Europe/London" time zone * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) + * ``` */ export const withCurrentZoneNamed: { (zone: string): ( @@ -1404,12 +1446,14 @@ export const withCurrentZoneNamed: { * @since 3.6.0 * @category current time zone * @example + * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function* () { * // will use the "Europe/London" time zone * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) + * ``` */ export const nowInCurrentZone: Effect.Effect = Effect.flatMap( now, @@ -1532,12 +1576,14 @@ export const mutateUtc: { * @since 3.6.0 * @category mapping * @example + * ```ts * import { DateTime } from "effect" * * // add 10 milliseconds * DateTime.unsafeMake(0).pipe( * DateTime.mapEpochMillis((millis) => millis + 10) * ) + * ``` */ export const mapEpochMillis: { (f: (millis: number) => number): (self: A) => DateTime.PreserveZone @@ -1554,12 +1600,14 @@ export const mapEpochMillis: { * @since 3.6.0 * @category mapping * @example + * ```ts * import { DateTime } from "effect" * * // get the time zone adjusted date in milliseconds * DateTime.unsafeMakeZoned(0, { timeZone: "Europe/London" }).pipe( * DateTime.withDate((date) => date.getTime()) * ) + * ``` */ export const withDate: { (f: (date: Date) => A): (self: DateTime) => A @@ -1573,12 +1621,14 @@ export const withDate: { * @since 3.6.0 * @category mapping * @example + * ```ts * import { DateTime } from "effect" * * // get the date in milliseconds * DateTime.unsafeMake(0).pipe( * DateTime.withDateUtc((date) => date.getTime()) * ) + * ``` */ export const withDateUtc: { (f: (date: Date) => A): (self: DateTime) => A @@ -1613,12 +1663,14 @@ export const match: { * @since 3.6.0 * @category math * @example + * ```ts * import { DateTime } from "effect" * * // add 5 minutes * DateTime.unsafeMake(0).pipe( * DateTime.addDuration("5 minutes") * ) + * ``` */ export const addDuration: { (duration: Duration.DurationInput): (self: A) => DateTime.PreserveZone @@ -1635,12 +1687,14 @@ export const addDuration: { * @since 3.6.0 * @category math * @example + * ```ts * import { DateTime } from "effect" * * // subtract 5 minutes * DateTime.unsafeMake(0).pipe( * DateTime.subtractDuration("5 minutes") * ) + * ``` */ export const subtractDuration: { (duration: Duration.DurationInput): (self: A) => DateTime.PreserveZone @@ -1664,12 +1718,14 @@ const addMillis = (date: Date, amount: number): void => { * @since 3.6.0 * @category math * @example + * ```ts * import { DateTime } from "effect" * * // add 5 minutes * DateTime.unsafeMake(0).pipe( * DateTime.add({ minutes: 5 }) * ) + * ``` */ export const add: { (parts: Partial): (self: A) => DateTime.PreserveZone @@ -1721,12 +1777,14 @@ export const add: { * @since 3.6.0 * @category math * @example + * ```ts * import { DateTime } from "effect" * * // subtract 5 minutes * DateTime.unsafeMake(0).pipe( * DateTime.subtract({ minutes: 5 }) * ) + * ``` */ export const subtract: { (parts: Partial): (self: A) => DateTime.PreserveZone @@ -1789,6 +1847,7 @@ function startOfDate(date: Date, part: DateTime.UnitSingular, options?: { * @since 3.6.0 * @category math * @example + * ```ts * import { DateTime } from "effect" * * // returns "2024-01-01T00:00:00Z" @@ -1796,6 +1855,7 @@ function startOfDate(date: Date, part: DateTime.UnitSingular, options?: { * DateTime.startOf("day"), * DateTime.formatIso * ) + * ``` */ export const startOf: { (part: DateTime.UnitSingular, options?: { @@ -1858,6 +1918,7 @@ function endOfDate(date: Date, part: DateTime.UnitSingular, options?: { * @since 3.6.0 * @category math * @example + * ```ts * import { DateTime } from "effect" * * // returns "2024-01-01T23:59:59.999Z" @@ -1865,6 +1926,7 @@ function endOfDate(date: Date, part: DateTime.UnitSingular, options?: { * DateTime.endOf("day"), * DateTime.formatIso * ) + * ``` */ export const endOf: { (part: DateTime.UnitSingular, options?: { @@ -1886,6 +1948,7 @@ export const endOf: { * @since 3.6.0 * @category math * @example + * ```ts * import { DateTime } from "effect" * * // returns "2024-01-02T00:00:00Z" @@ -1893,6 +1956,7 @@ export const endOf: { * DateTime.nearest("day"), * DateTime.formatIso * ) + * ``` */ export const nearest: { (part: DateTime.UnitSingular, options?: { diff --git a/packages/effect/src/Duration.ts b/packages/effect/src/Duration.ts index 1af113a5b50..b976453f798 100644 --- a/packages/effect/src/Duration.ts +++ b/packages/effect/src/Duration.ts @@ -796,10 +796,12 @@ export const parts = (self: DurationInput): { * @since 2.0.0 * @category conversions * @example + * ```ts * import { Duration } from "effect" * * Duration.format(Duration.millis(1000)) // "1s" * Duration.format(Duration.millis(1001)) // "1s 1ms" + * ``` */ export const format = (self: DurationInput): string => { const duration = decode(self) diff --git a/packages/effect/src/Effect.ts b/packages/effect/src/Effect.ts index d2f25774b54..afbc5329082 100644 --- a/packages/effect/src/Effect.ts +++ b/packages/effect/src/Effect.ts @@ -256,6 +256,7 @@ export const isEffect: (u: unknown) => u is Effect = * be recomputed upon next evaluation. * * @example + * ```ts * import { Effect, Console } from "effect" * * let i = 1 @@ -283,6 +284,7 @@ export const isEffect: (u: unknown) => u is Effect = * // result 1 * // expensive task... * // result 2 + * ``` * * @since 2.0.0 * @category Caching @@ -298,6 +300,7 @@ export const cachedWithTTL: { * invalidating the cached value before it naturally expires. * * @example + * ```ts * import { Effect, Console } from "effect" * * let i = 1 @@ -328,6 +331,7 @@ export const cachedWithTTL: { * // result 1 * // expensive task... * // result 2 + * ``` * * @since 2.0.0 * @category Caching @@ -348,6 +352,7 @@ export const cachedInvalidateWithTTL: { * the logic. * * @example + * ```ts * import { Effect, Console } from "effect" * * let i = 1 @@ -381,6 +386,7 @@ export const cachedInvalidateWithTTL: { * // expensive task... * // result 3 * // result 3 + * ``` * * @since 2.0.0 * @category Caching @@ -393,6 +399,7 @@ export const cached: (self: Effect) => Effect> * recompute them. * * @example + * ```ts * import { Effect, Random } from "effect" * * const program = Effect.gen(function* () { @@ -415,6 +422,7 @@ export const cached: (self: Effect) => Effect> * // memoized version: * // 5 * // 5 + * ``` * * @since 2.0.0 * @category Caching @@ -429,6 +437,7 @@ export const cachedFunction: ( * called. * * @example + * ```ts * import { Effect, Console } from "effect" * * const program = Effect.gen(function* () { @@ -444,6 +453,7 @@ export const cachedFunction: ( * // task1 * // task1 * // task2 + * ``` * * @since 2.0.0 * @category Caching @@ -500,6 +510,7 @@ export const once: (self: Effect) => Effect * @see {@link forEach} for iterating over elements and applying an effect. * * @example + * ```ts * // Title: Combining Effects in Tuples * import { Effect, Console } from "effect" * @@ -517,6 +528,7 @@ export const once: (self: Effect) => Effect * // 42 * // Hello * // [ 42, 'Hello' ] + * ``` * * @example * // Title: Combining Effects in Iterables @@ -675,6 +687,7 @@ export const all: < * your data and then apply operations to it. * * @example + * ```ts * import { Effect, pipe } from "effect" * * const task1 = Effect.succeed(1).pipe( @@ -698,6 +711,7 @@ export const all: < * // timestamp=... level=INFO fiber=#3 message="task2 done" * // timestamp=... level=INFO fiber=#2 message="task1 done" * // [ 1, 'hello' ] + * ``` * * @since 2.0.0 * @category Collecting @@ -942,6 +956,7 @@ export const filter: { * @see {@link filter} for concurrent filtering without mapping. * * @example + * ```ts * import { Console, Effect, Option } from "effect" * * const task = (n: number) => @@ -962,6 +977,7 @@ export const filter: { * // task3 done * // task4 done * // [ 2, 4 ] + * ``` * * @since 2.0.0 * @category Filtering @@ -1016,6 +1032,7 @@ export const findFirst: { * @see {@link all} for combining multiple effects into one. * * @example + * ```ts * // Title: Applying Effects to Iterable Elements * import { Effect, Console } from "effect" * @@ -1031,6 +1048,7 @@ export const findFirst: { * // Currently at index 3 * // Currently at index 4 * // [ 2, 4, 6, 8, 10 ] + * ``` * * @example * // Title: Using discard to Ignore Results @@ -1158,6 +1176,7 @@ export const mergeAll: { * @see {@link validateFirst} for a function that stops at the first success. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect<[string[], number[]], never, never> @@ -1173,6 +1192,7 @@ export const mergeAll: { * Effect.runPromise(program).then(console.log, console.error) * // Output: * // [ [ '1 is not even', '3 is not even' ], [ 0, 2, 4 ] ] + * ``` * * @since 2.0.0 * @category Error Accumulation @@ -1382,6 +1402,7 @@ export const takeWhile: { * @see {@link partition} when you need to separate successes and failures instead of losing successes with errors. * * @example + * ```ts * import { Effect, Console } from "effect" * * // ┌─── Effect @@ -1408,6 +1429,7 @@ export const takeWhile: { * // failure: [ '4 is not less that 4', '5 is not less that 4' ] * // } * // } + * ``` * * @since 2.0.0 * @category Error Accumulation @@ -1469,6 +1491,7 @@ export const validateAll: { * @see {@link firstSuccessOf} for a similar function that processes multiple effects and returns the first successful one or the last error. * * @example + * ```ts * import { Effect, Console } from "effect" * * // ┌─── Effect @@ -1485,6 +1508,7 @@ export const validateAll: { * // Output: * // item 4 * // 4 + * ``` * * @since 2.0.0 * @category Error Accumulation @@ -1538,6 +1562,7 @@ export const validateFirst: { * behavior of the returned effect. * * @example + * ```ts * // Title: Wrapping a Callback API * import { Effect } from "effect" * import * as NodeFS from "node:fs" @@ -1558,6 +1583,7 @@ export const validateFirst: { * // ┌─── Effect * // ▼ * const program = readFile("example.txt") + * ``` * * @example * // Title: Handling Interruption with Cleanup @@ -1655,12 +1681,14 @@ export const asyncEffect: ( * the "this" of the effect. * * @example + * ```ts * import { Effect } from "effect" * * const throwingFunction = () => { throw new Error() } * const blowUp = Effect.custom(throwingFunction, function() { * return Effect.succeed(this.effect_instruction_i0()) * }) + * ``` * * @since 2.0.0 * @category Creating Effects @@ -1703,6 +1731,7 @@ export const withFiberRuntime: ( * @see {@link succeed} to create an effect that represents a successful value. * * @example + * ```ts * // Title: Creating a Failed Effect * import { Effect } from "effect" * @@ -1711,6 +1740,7 @@ export const withFiberRuntime: ( * const failure = Effect.fail( * new Error("Operation failed due to network error") * ) + * ``` * * @since 2.0.0 * @category Creating Effects @@ -1756,6 +1786,7 @@ export const failCauseSync: (evaluate: LazyArg>) => Effect(evaluate: LazyArg>) => Effect Effect = core.die * lazily. * * @example + * ```ts * // Title: Terminating on Division by Zero with a Specified Message * import { Effect } from "effect" * @@ -1817,6 +1850,7 @@ export const die: (defect: unknown) => Effect = core.die * // Output: * // (FiberFailure) RuntimeException: Cannot divide by zero * // ...stack trace... + * ``` * * @since 2.0.0 * @category Creating Effects @@ -1852,6 +1886,7 @@ export const dieSync: (evaluate: LazyArg) => Effect = core.dieSy * effects and return the final result at the end. * * @example + * ```ts * import { Effect } from "effect" * * const addServiceCharge = (amount: number) => amount + 1 @@ -1878,6 +1913,7 @@ export const dieSync: (evaluate: LazyArg) => Effect = core.dieSy * const finalAmount = addServiceCharge(discountedAmount) * return `Final amount to charge: ${finalAmount}` * }) + * ``` * * @since 2.0.0 * @category Creating Effects @@ -2211,6 +2247,7 @@ export const none: ( * @see {@link tryPromise} for a version that can handle failures. * * @example + * ```ts * // Title: Delayed Message * import { Effect } from "effect" * @@ -2227,6 +2264,7 @@ export const none: ( * // ┌─── Effect * // ▼ * const program = delay("Async operation completed successfully!") + * ``` * * @since 2.0.0 * @category Creating Effects @@ -2246,6 +2284,7 @@ export const promise: ( * @see {@link fail} to create an effect that represents a failure. * * @example + * ```ts * // Title: Creating a Successful Effect * import { Effect } from "effect" * @@ -2254,6 +2293,7 @@ export const promise: ( * // ┌─── Effect * // ▼ * const success = Effect.succeed(42) + * ``` * * @since 2.0.0 * @category Creating Effects @@ -2291,6 +2331,7 @@ export const succeedSome: (value: A) => Effect> = effect.suc * - **Unifying Return Types**: Can help TypeScript unify return types in situations where multiple branches of logic return different effects, simplifying type inference. * * @example + * ```ts * // Title: Lazy Evaluation with Side Effects * import { Effect } from "effect" * @@ -2305,6 +2346,7 @@ export const succeedSome: (value: A) => Effect> = effect.suc * * console.log(Effect.runSync(good)) // Output: 1 * console.log(Effect.runSync(good)) // Output: 2 + * ``` * * @example * // Title: Recursive Fibonacci @@ -2378,6 +2420,7 @@ export const suspend: (effect: LazyArg>) => Effect(effect: LazyArg>) => Effect * // ▼ * const program = log("Hello, World!") + * ``` * * @since 2.0.0 * @category Creating Effects @@ -2450,6 +2494,7 @@ export { * @see {@link catchAllCause} for a version that can recover from both recoverable and unrecoverable errors. * * @example + * ```ts * // Title: Providing Recovery Logic for Recoverable Errors * import { Effect, Random } from "effect" * @@ -2482,6 +2527,7 @@ export { * Effect.succeed(`Recovering from ${error._tag}`) * ) * ) + * ``` * * @since 2.0.0 * @category Error handling @@ -2509,6 +2555,7 @@ export const catchAll: { * dynamically loaded plugins, controlled recovery might be needed. * * @example + * ```ts * // Title: Recovering from All Errors * import { Cause, Effect } from "effect" * @@ -2526,6 +2573,7 @@ export const catchAll: { * * Effect.runPromise(recovered).then(console.log) * // Output: "Recovered from a regular error" + * ``` * * @since 2.0.0 * @category Error handling @@ -2564,6 +2612,7 @@ export const catchAllCause: { * dynamically loaded plugins, controlled recovery might be needed. * * @example + * ```ts * // Title: Handling All Defects * import { Effect, Cause, Console } from "effect" * @@ -2588,6 +2637,7 @@ export const catchAllCause: { * // _tag: "Success", * // value: undefined * // } + * ``` * * @since 2.0.0 * @category Error handling @@ -2614,6 +2664,7 @@ export const catchAllDefect: { * error type unless a user-defined type guard is used to narrow the type. * * @example + * ```ts * // Title: Catching Specific Errors with a Predicate * import { Effect, Random } from "effect" * @@ -2648,6 +2699,7 @@ export const catchAllDefect: { * () => Effect.succeed("Recovering from HttpError") * ) * ) + * ``` * * @since 2.0.0 * @category Error handling @@ -2688,6 +2740,7 @@ export const catchIf: { * @see {@link catchIf} for a version that allows you to recover from errors based on a predicate. * * @example + * ```ts * // Title: Handling Specific Errors with Effect.catchSome * import { Effect, Random, Option } from "effect" * @@ -2725,6 +2778,7 @@ export const catchIf: { * } * }) * ) + * ``` * * @since 2.0.0 * @category Error handling @@ -2782,6 +2836,7 @@ export const catchSomeCause: { * - If the defect does not match, the function returns `Option.none`, allowing the defect to propagate. * * @example + * ```ts * // Title: Handling Specific Defects * import { Effect, Cause, Option, Console } from "effect" * @@ -2812,6 +2867,7 @@ export const catchSomeCause: { * // defect: { _tag: 'RuntimeException' } * // } * // } + * ``` * * @since 2.0.0 * @category Error handling @@ -2844,6 +2900,7 @@ export const catchSomeDefect: { * types at once. * * @example + * ```ts * // Title: Handling Errors by Tag * import { Effect, Random } from "effect" * @@ -2877,6 +2934,7 @@ export const catchSomeDefect: { * Effect.succeed("Recovering from HttpError") * ) * ) + * ``` * * @since 2.0.0 * @category Error handling @@ -2908,6 +2966,7 @@ export const catchTag: { * field is used to identify and match errors. * * @example + * ```ts * // Title: Handling Multiple Tagged Error Types at Once * import { Effect, Random } from "effect" * @@ -2943,6 +3002,7 @@ export const catchTag: { * Effect.succeed(`Recovering from ValidationError`) * }) * ) + * ``` * * @since 2.0.0 * @category Error handling @@ -3009,6 +3069,7 @@ export const catchTags: { * interruptions, etc.). * * @example + * ```ts * import { Effect, Console } from "effect" * * // ┌─── Effect @@ -3021,6 +3082,7 @@ export const catchTags: { * const cause = yield* Effect.cause(program) * yield* Console.log(cause) * }) + * ``` * * @since 2.0.0 * @category Error handling @@ -3044,6 +3106,7 @@ export const eventually: (self: Effect) => Effect * side effects of the effect and do not need to handle or process its outcome. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect @@ -3053,6 +3116,7 @@ export const eventually: (self: Effect) => Effect * // ┌─── Effect * // ▼ * const program = Effect.ignore(task) + * ``` * * @since 2.0.0 * @category Error handling @@ -3080,6 +3144,7 @@ export const ignoreLogged: (self: Effect) => Effect(self: Effect) => Effect(self: Effect) => Effect @@ -3154,6 +3221,7 @@ export const parallelErrors: (self: Effect) => Effect * // ▼ * const program = getTodo(1) + * ``` * * @example * // Title: Custom Error Handling @@ -3559,6 +3635,7 @@ export const checkInterruptible: (f: (isInterruptible: boolean) => Effe * @see {@link Effect.uninterruptible} for creating an uninterruptible effect. * * @example + * ```ts * import { Effect } from "effect" * * const longRunningTask = Effect.gen(function* () { @@ -3588,6 +3665,7 @@ export const checkInterruptible: (f: (isInterruptible: boolean) => Effe * // } * // } * // Heavy processing done. + * ``` * * @since 2.0.0 * @category Interruption @@ -3653,6 +3731,7 @@ export const uninterruptibleMask: ( * or failing with specified error if the predicate fails * * @example + * ```ts * import { Effect } from "effect" * * const isPositive = (n: number): boolean => n > 0 @@ -3662,6 +3741,7 @@ export const uninterruptibleMask: ( * * // fails with `"0 is not positive"` * Effect.liftPredicate(0, isPositive, n => `${n} is not positive`) + * ``` * * @category Condition Checking * @since 3.4.0 @@ -3683,6 +3763,7 @@ export const liftPredicate: { * replace it with a new constant value. * * @example + * ```ts * // Title: Replacing a Value * import { pipe, Effect } from "effect" * @@ -3691,6 +3772,7 @@ export const liftPredicate: { * * Effect.runPromise(program).then(console.log) * // Output: "new value" + * ``` * * @since 2.0.0 * @category Mapping @@ -3741,6 +3823,7 @@ export const asVoid: (self: Effect) => Effect = co * treat an error as a valid result. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect @@ -3750,6 +3833,7 @@ export const asVoid: (self: Effect) => Effect = co * // ┌─── Effect * // ▼ * const flipped = Effect.flip(program) + * ``` * * @since 2.0.0 * @category Mapping @@ -3800,6 +3884,7 @@ export const flipWith: { * @see {@link flatMap} or {@link andThen} for a version that can return a new effect. * * @example + * ```ts * // Title: Adding a Service Charge * import { pipe, Effect } from "effect" * @@ -3814,6 +3899,7 @@ export const flipWith: { * * Effect.runPromise(finalAmount).then(console.log) * // Output: 101 + * ``` * @since 2.0.0 * @category Mapping */ @@ -3842,6 +3928,7 @@ export const map: { * input collection type. * * @example + * ```ts * import { Effect } from "effect" * * // Define an initial state and a transformation function @@ -3860,6 +3947,7 @@ export const map: { * // Output: * // 6 * // [ 'A', 'BB', 'CCC' ] + * ``` * * @since 2.0.0 * @category Mapping @@ -3889,6 +3977,7 @@ export const mapAccum: { * @see {@link mapError} for a version that operates on the error channel. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect @@ -3901,6 +3990,7 @@ export const mapAccum: { * onFailure: (message) => new Error(message), * onSuccess: (n) => n > 0 * }) + * ``` * * @since 2.0.0 * @category Mapping @@ -3929,6 +4019,7 @@ export const mapBoth: { * @see {@link orElseFail} if you want to replace the error with a new one. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect @@ -3941,6 +4032,7 @@ export const mapBoth: { * simulatedTask, * (message) => new Error(message) * ) + * ``` * * @since 2.0.0 * @category Mapping @@ -3976,6 +4068,7 @@ export const mapErrorCause: { * errors as part of the outcome. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect @@ -3985,6 +4078,7 @@ export const mapErrorCause: { * // ┌─── Effect * // ▼ * const recovered = Effect.merge(program) + * ``` * * @since 2.0.0 * @category Mapping @@ -4659,6 +4753,7 @@ export const timedWith: { * @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers. * * @example + * ```ts * import { Effect } from "effect" * * const task = Effect.gen(function* () { @@ -4684,6 +4779,7 @@ export const timedWith: { * // failure: { _tag: 'TimeoutException' } * // } * // } + * ``` * * @since 2.0.0 * @category delays & timeouts @@ -4713,6 +4809,7 @@ export const timeout: { * @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers. * * @example + * ```ts * import { Effect } from "effect" * * const task = Effect.gen(function* () { @@ -4736,6 +4833,7 @@ export const timeout: { * // { _id: 'Option', _tag: 'Some', value: 'Result' }, * // { _id: 'Option', _tag: 'None' } * // ] + * ``` * * @since 3.1.0 * @category delays & timeouts @@ -4764,6 +4862,7 @@ export const timeoutOption: { * @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers. * * @example + * ```ts * import { Effect } from "effect" * * const task = Effect.gen(function* () { @@ -4796,6 +4895,7 @@ export const timeoutOption: { * // failure: MyTimeoutError { _tag: 'MyTimeoutError' } * // } * // } + * ``` * * @since 2.0.0 * @category delays & timeouts @@ -4828,6 +4928,7 @@ export const timeoutFail: { * @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers. * * @example + * ```ts * import { Effect, Cause } from "effect" * * const task = Effect.gen(function* () { @@ -4852,6 +4953,7 @@ export const timeoutFail: { * // _tag: 'Failure', * // cause: { _id: 'Cause', _tag: 'Die', defect: 'Timed out!' } * // } + * ``` * * @since 2.0.0 * @category delays & timeouts @@ -4888,6 +4990,7 @@ export const timeoutFailCause: { * @see {@link timeoutFailCause} for a version that raises a custom defect. * * @example + * ```ts * import { Effect, Either } from "effect" * * const task = Effect.gen(function* () { @@ -4915,6 +5018,7 @@ export const timeoutFailCause: { * // _tag: "Left", * // left: "Timed out!" * // } + * ``` * * @since 2.0.0 * @category delays & timeouts @@ -5015,6 +5119,7 @@ export const mapInputContext: { * @see {@link provideService} for providing a service to an effect. * * @example + * ```ts * import { Context, Effect, Layer } from "effect" * * class Database extends Context.Tag("Database")< @@ -5046,6 +5151,7 @@ export const mapInputContext: { * // Output: * // timestamp=... level=INFO fiber=#0 message="Executing query: SELECT * FROM users" * // [] + * ``` * * @since 2.0.0 * @category Context @@ -5103,6 +5209,7 @@ export const provide: { * @see {@link provide} for providing multiple layers to an effect. * * @example + * ```ts * import { Effect, Context } from "effect" * * // Declaring a tag for a service that generates random numbers @@ -5130,6 +5237,7 @@ export const provide: { * Effect.runPromise(runnable) * // Example Output: * // random number: 0.8241872233134417 + * ``` * * @since 2.0.0 * @category Context @@ -5270,6 +5378,7 @@ export const updateService: { * @see {@link let_ let} * * @example + * ```ts * import { Effect, pipe } from "effect" * * const result = pipe( @@ -5279,6 +5388,7 @@ export const updateService: { * Effect.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 }) + * ``` * * @category Do notation * @since 2.0.0 @@ -5300,6 +5410,7 @@ export const Do: Effect<{}> = effect.Do * @see {@link let_ let} * * @example + * ```ts * import { Effect, pipe } from "effect" * * const result = pipe( @@ -5309,6 +5420,7 @@ export const Do: Effect<{}> = effect.Do * Effect.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 }) + * ``` * * @category Do notation * @since 2.0.0 @@ -5331,6 +5443,7 @@ export const bind: { * results in a Do notation pipeline. * * @example + * ```ts * import { Effect, Either, pipe } from "effect" * * const result = pipe( @@ -5342,6 +5455,7 @@ export const bind: { * }), { concurrency: 2, mode: "either" }) * ) * assert.deepStrictEqual(Effect.runSync(result), { x: 2, a: Either.right(2), b: Either.left("oops") }) + * ``` * * @category Do notation * @since 3.7.0 @@ -5412,6 +5526,7 @@ export const bindAll: { * @see {@link let_ let} * * @example + * ```ts * import { Effect, pipe } from "effect" * * const result = pipe( @@ -5421,6 +5536,7 @@ export const bindAll: { * Effect.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 }) + * ``` * * @category Do notation * @since 2.0.0 @@ -5458,6 +5574,7 @@ export { * @see {@link bindTo} * * @example + * ```ts * import { Effect, pipe } from "effect" * * const result = pipe( @@ -5468,6 +5585,7 @@ export { * ) * assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 }) * + * ``` * @category Do notation * @since 2.0.0 */ @@ -5492,6 +5610,7 @@ export { * @see {@link exit} for a version that uses `Exit` instead. * * @example + * ```ts * // Title: Using Effect.option to Handle Errors * import { Effect } from "effect" * @@ -5524,6 +5643,7 @@ export { * // _tag: 'Failure', * // cause: { _id: 'Cause', _tag: 'Die', defect: 'Boom!' } * // } + * ``` * * @since 2.0.0 * @category Outcome Encapsulation @@ -5549,6 +5669,7 @@ export const option: (self: Effect) => Effect * @see {@link exit} for a version that uses `Exit` instead. * * @example + * ```ts * import { Effect, Either, Random } from "effect" * * class HttpError { @@ -5584,6 +5705,7 @@ export const option: (self: Effect) => Effect * onRight: (value) => value // Do nothing in case of success * }) * }) + * ``` * * @since 2.0.0 * @category Outcome Encapsulation @@ -5607,6 +5729,7 @@ export const either: (self: Effect) => Effect(self: Effect) => Effect(self: Effect) => Effect, n * failure. Additionally, if the effect is interrupted, the `Deferred` will also be interrupted. * * @example + * ```ts * import { Deferred, Effect } from "effect" * * // Define an effect that succeeds @@ -5678,6 +5803,7 @@ export const exit: (self: Effect) => Effect, n * // Output: * // 42 * // true + * ``` * * @since 2.0.0 * @category Synchronization Utilities @@ -5706,6 +5832,7 @@ export { * is executed. If it is `false`, the `onFalse` effect is executed instead. * * @example + * ```ts * // Title: Simulating a Coin Flip * import { Effect, Random, Console } from "effect" * @@ -5716,6 +5843,7 @@ export { * * Effect.runFork(flipTheCoin) * + * ``` * @since 2.0.0 * @category Conditional Operators */ @@ -5802,6 +5930,7 @@ export const filterOrElse: { * Let's explore this concept through an example: * * @example + * ```ts * import { Effect, pipe } from "effect" * * // Define a user interface @@ -5822,6 +5951,7 @@ export const filterOrElse: { * // 'user' now has the type `User` (not `User | null`) * Effect.andThen((user) => user.name) * ) + * ``` * * @since 2.0.0 * @category Filtering @@ -5900,6 +6030,7 @@ export const unlessEffect: { * @see {@link unless} for a version that executes the effect when the condition is `false`. * * @example + * ```ts * // Title: Conditional Effect Execution * import { Effect, Option } from "effect" * @@ -5925,6 +6056,7 @@ export const unlessEffect: { * // _id: "Option", * // _tag: "None" * // } + * ``` * * @since 2.0.0 * @category Conditional Operators @@ -5952,6 +6084,7 @@ export const when: { * @see {@link unlessEffect} for a version that executes the effect when the condition is `false`. * * @example + * ```ts * // Title: Using an Effect as a Condition * import { Effect, Random } from "effect" * @@ -5962,6 +6095,7 @@ export const when: { * console.log(Effect.runSync(randomIntOption)) * // Example Output: * // { _id: 'Option', _tag: 'Some', value: 8609104974198840 } + * ``` * * @since 2.0.0 * @category Conditional Operators @@ -6033,6 +6167,7 @@ export const whenRef: { * changing the original one. * * @example + * ```ts * import { pipe, Effect } from "effect" * * // Function to apply a discount safely to a transaction amount @@ -6055,6 +6190,7 @@ export const whenRef: { * * Effect.runPromise(finalAmount).then(console.log) * // Output: 95 + * ``` * * @since 2.0.0 * @category sequencing @@ -6098,6 +6234,7 @@ export const flatMap: { * treating them as effects. * * @example + * ```ts * // Title: Applying a Discount Based on Fetched Amount * import { pipe, Effect } from "effect" * @@ -6132,6 +6269,7 @@ export const flatMap: { * * Effect.runPromise(result2).then(console.log) * // Output: 190 + * ``` * * @since 2.0.0 * @category sequencing @@ -6281,6 +6419,7 @@ export const summarized: { * will fail too. * * @example + * ```ts * // Title: Logging a step in a pipeline * import { Console, Effect, pipe } from "effect" * @@ -6308,6 +6447,7 @@ export const summarized: { * // Output: * // Apply a discount to: 100 * // 95 + * ``` * * @since 2.0.0 * @category sequencing @@ -6375,6 +6515,7 @@ export const tap: { * altering the result. * * @example + * ```ts * import { Effect, Random, Console } from "effect" * * // Simulate a task that might fail @@ -6394,6 +6535,7 @@ export const tap: { * Effect.runFork(tapping) * // Example Output: * // failure: random number is negative + * ``` * * @since 2.0.0 * @category sequencing @@ -6425,6 +6567,7 @@ export const tapBoth: { * severe errors. * * @example + * ```ts * import { Effect, Console } from "effect" * * // Simulate a task that fails with a recoverable error @@ -6452,6 +6595,7 @@ export const tapBoth: { * // Output: * // defect: RuntimeException: Something went wrong * // ... stack trace ... + * ``` * * @since 2.0.0 * @category sequencing @@ -6476,6 +6620,7 @@ export const tapDefect: { * while the operation you provide can inspect or act on it. * * @example + * ```ts * import { Effect, Console } from "effect" * * // Simulate a task that fails with an error @@ -6489,6 +6634,7 @@ export const tapDefect: { * Effect.runFork(tapping) * // Output: * // expected error: NetworkError + * ``` * * @since 2.0.0 * @category sequencing @@ -6510,6 +6656,7 @@ export const tapError: { * without modifying the error or the overall result of the effect. * * @example + * ```ts * import { Effect, Console } from "effect" * * class NetworkError { @@ -6534,6 +6681,7 @@ export const tapError: { * Effect.runFork(tapping) * // Output: * // expected error: 504 + * ``` * * @since 2.0.0 * @category sequencing @@ -6560,6 +6708,7 @@ export const tapErrorTag: { * altering the error or the overall result of the effect. * * @example + * ```ts * import { Effect, Console } from "effect" * * // Create a task that fails with a NetworkError @@ -6586,6 +6735,7 @@ export const tapErrorTag: { * // Output: * // error cause: RuntimeException: Something went wrong * // ... stack trace ... + * ``` * * @since 2.0.0 * @category sequencing @@ -6627,6 +6777,7 @@ export const forever: (self: Effect) => Effect = * ``` * * @example + * ```ts * // Title: Effectful Iteration * import { Effect } from "effect" * @@ -6643,6 +6794,7 @@ export const forever: (self: Effect) => Effect = * * Effect.runPromise(result).then(console.log) * // Output: 6 + * ``` * * @since 2.0.0 * @category Looping @@ -6691,6 +6843,7 @@ export const iterate: { * discarded, and the final result will be `void`. * * @example + * ```ts * // Title: Looping with Collected Results * import { Effect } from "effect" * @@ -6710,6 +6863,7 @@ export const iterate: { * * Effect.runPromise(result).then(console.log) * // Output: [1, 2, 3, 4, 5] + * ``` * * @example * // Title: Loop with Discarded Results @@ -6823,6 +6977,7 @@ export declare namespace Repeat { * an additional time. * * @example + * ```ts * // Success Example * import { Effect, Schedule, Console } from "effect" * @@ -6831,6 +6986,7 @@ export declare namespace Repeat { * const program = Effect.repeat(action, policy) * * Effect.runPromise(program).then((n) => console.log(`repetitions: ${n}`)) + * ``` * * @example * // Failure Example @@ -6881,12 +7037,14 @@ export const repeat: { * initially and then repeats it one additional time if it succeeds. * * @example + * ```ts * import { Effect, Console } from "effect" * * const action = Console.log("success") * const program = Effect.repeatN(action, 2) * * Effect.runPromise(program) + * ``` * * @since 2.0.0 * @category repetition / recursion @@ -6905,6 +7063,7 @@ export const repeatN: { * initially and then repeats it an additional time if it succeeds. * * @example + * ```ts * import { Effect, Schedule } from "effect" * * let count = 0 @@ -6934,6 +7093,7 @@ export const repeatN: { * ) * * Effect.runPromise(program).then((n) => console.log(`repetitions: ${n}`)) + * ``` * * @since 2.0.0 * @category repetition / recursion @@ -7123,6 +7283,7 @@ export const isSuccess: (self: Effect) => Effect = Effect.succeed(42) @@ -7148,6 +7309,7 @@ export const isSuccess: (self: Effect) => Effect = Effect.die("Uh oh!") @@ -7240,6 +7403,7 @@ export const matchCause: { * * Effect.runSync(program) * // Output: "Die: Uh oh!" + * ``` * * @since 2.0.0 * @category getters & folding @@ -7298,6 +7462,7 @@ export const matchEffect: { * To adjust the log level, use the `Logger.withMinimumLogLevel` function. * * @example + * ```ts * import { Cause, Effect } from "effect" * * const program = Effect.log( @@ -7311,6 +7476,7 @@ export const matchEffect: { * // Output: * // timestamp=... level=INFO fiber=#0 message=message1 message=message2 cause="Error: Oh no! * // Error: Oh uh!" + * ``` * * @since 2.0.0 * @category Logging @@ -7344,12 +7510,14 @@ export const logTrace: (...message: ReadonlyArray) => Effect) => Effect) => Effect(self: Effect) => Effect = co * @see {@link orDie} if you don't need to customize the error. * * @example + * ```ts * // Title: Customizing Defect * import { Effect } from "effect" * @@ -7563,6 +7740,7 @@ export const orDie: (self: Effect) => Effect = co * // Output: * // (FiberFailure) Error: defect: Cannot divide by zero * // ...stack trace... + * ``` * * @since 2.0.0 * @category Converting Failures to Defects @@ -7583,6 +7761,7 @@ export const orDieWith: { * @see {@link catchAll} if you need to access the error in the fallback effect. * * @example + * ```ts * import { Effect } from "effect" * * const success = Effect.succeed("success") @@ -7598,6 +7777,7 @@ export const orDieWith: { * const program2 = Effect.orElse(failure, () => fallback) * console.log(Effect.runSync(program2)) * // Output: "fallback" + * ``` * * @since 2.0.0 * @category Fallback @@ -7620,6 +7800,7 @@ export const orElse: { * @see {@link mapError} if you need to access the error to transform it. * * @example + * ```ts * import { Effect } from "effect" * * const validate = (age: number): Effect.Effect => { @@ -7641,6 +7822,7 @@ export const orElse: { * // _tag: 'Failure', * // cause: { _id: 'Cause', _tag: 'Fail', failure: 'invalid age' } * // } + * ``` * * @since 2.0.0 * @category Fallback @@ -7668,6 +7850,7 @@ export const orElseFail: { * already succeeds, it will remain unchanged. * * @example + * ```ts * import { Effect } from "effect" * * const validate = (age: number): Effect.Effect => { @@ -7685,6 +7868,7 @@ export const orElseFail: { * console.log(Effect.runSyncExit(program)) * // Output: * // { _id: 'Exit', _tag: 'Success', value: 18 } + * ``` * * @since 2.0.0 * @category Fallback @@ -7712,6 +7896,7 @@ export const orElseSucceed: { * error. * * @example + * ```ts * import { Effect, Console } from "effect" * * interface Config { @@ -7758,6 +7943,7 @@ export const orElseSucceed: { * // Unavailable config for node2 * // Config for node3 found * // { host: 'node3.example.com', port: 8080, apiKey: '12345-abcde' } + * ``` * * @since 2.0.0 * @category Fallback @@ -7998,6 +8184,7 @@ export const unsafeMakeLatch: (open?: boolean | undefined) => Latch = circular.u * @category latch * @since 3.8.0 * @example + * ```ts * import { Effect } from "effect" * * Effect.gen(function*() { @@ -8014,6 +8201,7 @@ export const unsafeMakeLatch: (open?: boolean | undefined) => Latch = circular.u * yield* latch.open * yield* fiber.await * }) + * ``` */ export const makeLatch: (open?: boolean | undefined) => Effect = circular.makeLatch @@ -8031,6 +8219,7 @@ export const makeLatch: (open?: boolean | undefined) => Effect Effect { * Effect.runFork(Fiber.interrupt(fiber)) * }, 500) + * ``` * * @since 2.0.0 * @category Running Effects @@ -8081,11 +8271,13 @@ export const runCallback: ( * @see {@link runPromiseExit} for a version that returns an `Exit` type instead of rejecting. * * @example + * ```ts * // Title: Running a Successful Effect as a Promise * import { Effect } from "effect" * * Effect.runPromise(Effect.succeed(1)).then(console.log) * // Output: 1 + * ``` * * @example * //Example: Handling a Failing Effect as a Rejected Promise @@ -8120,6 +8312,7 @@ export const runPromise: ( * a `Cause` type. * * @example + * ```ts * // Title: Handling Results as Exit * import { Effect } from "effect" * @@ -8144,6 +8337,7 @@ export const runPromise: ( * // failure: "my error" * // } * // } + * ``` * * @since 2.0.0 * @category Running Effects @@ -8169,6 +8363,7 @@ export const runPromiseExit: ( * throwing an error. * * @example + * ```ts * // Title: Synchronous Logging * import { Effect } from "effect" * @@ -8182,6 +8377,7 @@ export const runPromiseExit: ( * * console.log(result) * // Output: 1 + * ``` * * @example * // Title: Incorrect Usage with Failing or Async Effects @@ -8231,6 +8427,7 @@ export const runSync: (effect: Effect) => A = _runtime.unsafeRunSync * resolved synchronously. * * @example + * ```ts * // Title: Handling Results as Exit * import { Effect } from "effect" * @@ -8253,6 +8450,7 @@ export const runSync: (effect: Effect) => A = _runtime.unsafeRunSync * // failure: "my error" * // } * // } + * ``` * * @example * // Title: Asynchronous Operation Resulting in Die @@ -8294,6 +8492,7 @@ export const runSyncExit: (effect: Effect) => Exit.Exit = _run * @see {@link zip} for a version that stops at the first error. * * @example + * ```ts * import { Effect, Console } from "effect" * * const task1 = Console.log("task1").pipe(Effect.as(1)) @@ -8321,6 +8520,7 @@ export const runSyncExit: (effect: Effect) => Exit.Exit = _run * // right: { _id: 'Cause', _tag: 'Fail', failure: 'Oh no!' } * // } * // } + * ``` * * @since 2.0.0 * @category Error Accumulation @@ -8395,6 +8595,7 @@ export const validateWith: { * @see {@link validate} for a version that accumulates errors. * * @example + * ```ts * // Title: Combining Two Effects Sequentially * import { Effect } from "effect" * @@ -8418,6 +8619,7 @@ export const validateWith: { * // timestamp=... level=INFO fiber=#0 message="task1 done" * // timestamp=... level=INFO fiber=#0 message="task2 done" * // [ 1, 'hello' ] + * ``` * * @example * // Title: Combining Two Effects Concurrently @@ -8486,6 +8688,7 @@ export const zip: { * @see {@link zipRight} for a version that returns the result of the second effect. * * @example + * ```ts * import { Effect } from "effect" * * const task1 = Effect.succeed(1).pipe( @@ -8504,6 +8707,7 @@ export const zip: { * // timestamp=... level=INFO fiber=#0 message="task1 done" * // timestamp=... level=INFO fiber=#0 message="task2 done" * // 1 + * ``` * * @since 2.0.0 * @category Zipping @@ -8550,6 +8754,7 @@ export const zipLeft: { * @see {@link zipLeft} for a version that returns the result of the first effect. * * @example + * ```ts * import { Effect } from "effect" * * const task1 = Effect.succeed(1).pipe( @@ -8568,6 +8773,7 @@ export const zipLeft: { * // timestamp=... level=INFO fiber=#0 message="task1 done" * // timestamp=... level=INFO fiber=#0 message="task2 done" * // hello + * ``` * * @since 2.0.0 * @category Zipping @@ -8608,6 +8814,7 @@ export const zipRight: { * use the `{ concurrent: true }` option. * * @example + * ```ts * // Title: Combining Effects with a Custom Function * import { Effect } from "effect" * @@ -8632,6 +8839,7 @@ export const zipRight: { * // timestamp=... level=INFO fiber=#3 message="task1 done" * // timestamp=... level=INFO fiber=#2 message="task2 done" * // 6 + * ``` * * @since 2.0.0 * @category Zipping @@ -8787,6 +8995,7 @@ export const withTracerScoped: (value: Tracer.Tracer) => Effect Effect(effect: Effect) => Effect @@ -8960,6 +9170,7 @@ export interface FunctionWithSpanOptions { * @since 3.2.0 * @category Tracing * @example + * ```ts * import { Effect } from "effect" * * const getTodo = Effect.functionWithSpan({ @@ -8969,6 +9180,7 @@ export interface FunctionWithSpanOptions { * attributes: { id } * }) * }) + * ``` */ export const functionWithSpan: , Ret extends Effect>( options: { @@ -9021,6 +9233,7 @@ export const withParentSpan: { * value. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect @@ -9046,6 +9259,7 @@ export const withParentSpan: { * // failure: { _tag: 'NoSuchElementException' } * // } * // } + * ``` * * @since 2.0.0 * @category Optional Wrapping @@ -9064,6 +9278,7 @@ export const fromNullable: (value: A) => Effect, Cause.NoSuchE * unchanged. * * @example + * ```ts * import { Effect } from "effect" * * // ┌─── Effect @@ -9087,6 +9302,7 @@ export const fromNullable: (value: A) => Effect, Cause.NoSuchE * * Effect.runPromise(option2).then(console.log) * // Output: { _tag: 'None' } + * ``` * * @since 2.0.0 * @category Optional Wrapping @@ -9173,6 +9389,7 @@ const makeTagProxy = (TagClass: Context.Tag & Record /** * @example + * ```ts * import { Effect, Layer } from "effect" * * class MapTag extends Effect.Tag("MapTag")>() { @@ -9181,6 +9398,7 @@ const makeTagProxy = (TagClass: Context.Tag & Record * Effect.sync(() => new Map()) * ) * } + * ``` * * @since 2.0.0 * @category Context @@ -9220,6 +9438,7 @@ export const Tag: (id: Id) => < /** * @example + * ```ts * import { Effect } from 'effect'; * * class Prefix extends Effect.Service()("Prefix", { @@ -9239,6 +9458,7 @@ export const Tag: (id: Id) => < * }), * dependencies: [Prefix.Default] * }) {} + * ``` * * @since 3.9.0 * @category Context diff --git a/packages/effect/src/Either.ts b/packages/effect/src/Either.ts index f65af6662b4..b7ffe6bb42c 100644 --- a/packages/effect/src/Either.ts +++ b/packages/effect/src/Either.ts @@ -130,10 +130,12 @@ export const left: (left: L) => Either = either.left * the provided default as a `Left`. * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1)) * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback')) + * ``` * * @category constructors * @since 2.0.0 @@ -149,10 +151,12 @@ export const fromNullable: { /** * @example + * ```ts * import { Either, Option } from "effect" * * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1)) * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error')) + * ``` * * @category constructors * @since 2.0.0 @@ -208,11 +212,13 @@ export { * @param input - The value to test. * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.isEither(Either.right(1)), true) * assert.deepStrictEqual(Either.isEither(Either.left("a")), true) * assert.deepStrictEqual(Either.isEither({ right: 1 }), false) + * ``` * * @category guards * @since 2.0.0 @@ -225,10 +231,12 @@ export const isEither: (input: unknown) => input is Either = e * @param self - The `Either` to check. * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false) * assert.deepStrictEqual(Either.isLeft(Either.left("a")), true) + * ``` * * @category guards * @since 2.0.0 @@ -241,10 +249,12 @@ export const isLeft: (self: Either) => self is Left = either.i * @param self - The `Either` to check. * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.isRight(Either.right(1)), true) * assert.deepStrictEqual(Either.isRight(Either.left("a")), false) + * ``` * * @category guards * @since 2.0.0 @@ -257,10 +267,12 @@ export const isRight: (self: Either) => self is Right = either * Alias of {@link toOption}. * * @example + * ```ts * import { Either, Option } from "effect" * * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok')) * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none()) + * ``` * * @category getters * @since 2.0.0 @@ -271,10 +283,12 @@ export const getRight: (self: Either) => Option = either.getRight * Converts a `Either` to an `Option` discarding the value. * * @example + * ```ts * import { Either, Option } from "effect" * * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none()) * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err')) + * ``` * * @category getters * @since 2.0.0 @@ -357,6 +371,7 @@ export const map: { * if the value is a `Right` the inner value is applied to the `onRight` function. * * @example + * ```ts * import { pipe, Either } from "effect" * * const onLeft = (strings: ReadonlyArray): string => `strings: ${strings.join(', ')}` @@ -368,6 +383,7 @@ export const map: { * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })), * 'strings: string 1, string 2' * ) + * ``` * * @category pattern matching * @since 2.0.0 @@ -396,6 +412,7 @@ export const match: { * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean. * * @example + * ```ts * import { pipe, Either } from "effect" * * const isPositive = (n: number): boolean => n > 0 @@ -414,6 +431,7 @@ export const match: { * ), * Either.left("0 is not positive") * ) + * ``` * * @category lifting * @since 3.4.0 @@ -445,6 +463,7 @@ export const liftPredicate: { * If the predicate fails, set the left value with the result of the provided function. * * @example + * ```ts * import { pipe, Either } from "effect" * * const isPositive = (n: number): boolean => n > 0 @@ -463,6 +482,7 @@ export const liftPredicate: { * ), * Either.left("0 is not positive") * ) + * ``` * * @since 2.0.0 * @category filtering & conditionals @@ -501,10 +521,12 @@ export const merge: (self: Either) => L | R = match({ * Returns the wrapped value if it's a `Right` or a default value if is a `Left`. * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + "!"), 1) * assert.deepStrictEqual(Either.getOrElse(Either.left("not a number"), (error) => error + "!"), "not a number!") + * ``` * * @category getters * @since 2.0.0 @@ -519,10 +541,12 @@ export const getOrElse: { /** * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1) * assert.deepStrictEqual(Either.getOrNull(Either.left("a")), null) + * ``` * * @category getters * @since 2.0.0 @@ -531,10 +555,12 @@ export const getOrNull: (self: Either) => R | null = getOrElse(const /** * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1) * assert.deepStrictEqual(Either.getOrUndefined(Either.left("a")), undefined) + * ``` * * @category getters * @since 2.0.0 @@ -550,6 +576,7 @@ export const getOrUndefined: (self: Either) => R | undefined = getOr * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown. * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual( @@ -557,6 +584,7 @@ export const getOrUndefined: (self: Either) => R | undefined = getOr * 1 * ) * assert.throws(() => Either.getOrThrowWith(Either.left("error"), () => new Error('Unexpected Left'))) + * ``` * * @category getters * @since 2.0.0 @@ -580,10 +608,12 @@ export const getOrThrowWith: { * @throws `Error("getOrThrow called on a Left")` * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1) * assert.throws(() => Either.getOrThrow(Either.left("error"))) + * ``` * * @category getters * @since 2.0.0 @@ -690,11 +720,13 @@ export const ap: { * @param fields - the struct of `Either`s to be sequenced. * * @example + * ```ts * import { Either } from "effect" * * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2])) * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right("hello") }), Either.right({ right: 1, b: "hello" })) * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left("error") }), Either.left("error")) + * ``` * * @category combining * @since 2.0.0 @@ -805,6 +837,7 @@ export const gen: Gen.Gen> = (.. * @see {@link let_ let} * * @example + * ```ts * import { Either, pipe } from "effect" * * const result = pipe( @@ -814,6 +847,7 @@ export const gen: Gen.Gen> = (.. * Either.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -835,6 +869,7 @@ export const Do: Either<{}> = right({}) * @see {@link let_ let} * * @example + * ```ts * import { Either, pipe } from "effect" * * const result = pipe( @@ -844,6 +879,7 @@ export const Do: Either<{}> = right({}) * Either.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -875,6 +911,7 @@ export const bind: { * @see {@link let_ let} * * @example + * ```ts * import { Either, pipe } from "effect" * * const result = pipe( @@ -884,6 +921,7 @@ export const bind: { * Either.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -921,6 +959,7 @@ export { * @see {@link bind} * * @example + * ```ts * import { Either, pipe } from "effect" * * const result = pipe( @@ -931,6 +970,7 @@ export { * ) * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 })) * + * ``` * @category do notation * @since 2.0.0 */ diff --git a/packages/effect/src/FiberHandle.ts b/packages/effect/src/FiberHandle.ts index 15a0cbb9160..85ff979e873 100644 --- a/packages/effect/src/FiberHandle.ts +++ b/packages/effect/src/FiberHandle.ts @@ -87,6 +87,7 @@ const unsafeMake = ( * be automatically removed from the FiberHandle when it completes. * * @example + * ```ts * import { Effect, FiberHandle } from "effect" * * Effect.gen(function*(_) { @@ -101,6 +102,7 @@ const unsafeMake = ( * }).pipe( * Effect.scoped // The fiber will be interrupted when the scope is closed * ) + * ``` * * @since 2.0.0 * @categories constructors @@ -380,6 +382,7 @@ export const run: { * Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberHandle. * * @example + * ```ts * import { Context, Effect, FiberHandle } from "effect" * * interface Users { @@ -401,6 +404,7 @@ export const run: { * }).pipe( * Effect.scoped // The fiber will be interrupted when the scope is closed * ) + * ``` * * @since 2.0.0 * @categories combinators @@ -452,6 +456,7 @@ export const runtime: ( * @since 2.0.0 * @categories combinators * @example + * ```ts * import { Effect, FiberHandle } from "effect"; * * Effect.gen(function* (_) { @@ -461,6 +466,7 @@ export const runtime: ( * // parent fiber will fail with "error" * yield* _(FiberHandle.join(handle)); * }); + * ``` */ export const join = (self: FiberHandle): Effect.Effect => Deferred.await(self.deferred as Deferred.Deferred) diff --git a/packages/effect/src/FiberMap.ts b/packages/effect/src/FiberMap.ts index 5d1b3b76dea..3bea30477df 100644 --- a/packages/effect/src/FiberMap.ts +++ b/packages/effect/src/FiberMap.ts @@ -98,6 +98,7 @@ const unsafeMake = ( * be automatically removed from the FiberMap when they complete. * * @example + * ```ts * import { Effect, FiberMap } from "effect" * * Effect.gen(function*(_) { @@ -111,6 +112,7 @@ const unsafeMake = ( * }).pipe( * Effect.scoped // The fibers will be interrupted when the scope is closed * ) + * ``` * * @since 2.0.0 * @categories constructors @@ -484,6 +486,7 @@ export const run: { * Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberMap. * * @example + * ```ts * import { Context, Effect, FiberMap } from "effect" * * interface Users { @@ -503,6 +506,7 @@ export const run: { * }).pipe( * Effect.scoped // The fibers will be interrupted when the scope is closed * ) + * ``` * * @since 2.0.0 * @categories combinators @@ -563,6 +567,7 @@ export const size = (self: FiberMap): Effect.Effect => * @since 2.0.0 * @categories combinators * @example + * ```ts * import { Effect, FiberMap } from "effect"; * * Effect.gen(function* (_) { @@ -572,6 +577,7 @@ export const size = (self: FiberMap): Effect.Effect => * // parent fiber will fail with "error" * yield* _(FiberMap.join(map)); * }); + * ``` */ export const join = (self: FiberMap): Effect.Effect => Deferred.await(self.deferred as Deferred.Deferred) diff --git a/packages/effect/src/FiberSet.ts b/packages/effect/src/FiberSet.ts index 75f3c7cc6f2..20ac5c2cdec 100644 --- a/packages/effect/src/FiberSet.ts +++ b/packages/effect/src/FiberSet.ts @@ -95,6 +95,7 @@ const unsafeMake = ( * be automatically removed from the FiberSet when they complete. * * @example + * ```ts * import { Effect, FiberSet } from "effect" * * Effect.gen(function*(_) { @@ -108,6 +109,7 @@ const unsafeMake = ( * }).pipe( * Effect.scoped // The fibers will be interrupted when the scope is closed * ) + * ``` * * @since 2.0.0 * @categories constructors @@ -322,6 +324,7 @@ export const run: { * Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberSet. * * @example + * ```ts * import { Context, Effect, FiberSet } from "effect" * * interface Users { @@ -340,6 +343,7 @@ export const run: { * }).pipe( * Effect.scoped // The fibers will be interrupted when the scope is closed * ) + * ``` * * @since 2.0.0 * @categories combinators @@ -387,6 +391,7 @@ export const size = (self: FiberSet): Effect.Effect => * @since 2.0.0 * @categories combinators * @example + * ```ts * import { Effect, FiberSet } from "effect"; * * Effect.gen(function* (_) { @@ -396,6 +401,7 @@ export const size = (self: FiberSet): Effect.Effect => * // parent fiber will fail with "error" * yield* _(FiberSet.join(set)); * }); + * ``` */ export const join = (self: FiberSet): Effect.Effect => Deferred.await(self.deferred as Deferred.Deferred) diff --git a/packages/effect/src/Function.ts b/packages/effect/src/Function.ts index 8f04fe5c739..e8d089d4dee 100644 --- a/packages/effect/src/Function.ts +++ b/packages/effect/src/Function.ts @@ -17,10 +17,12 @@ export interface FunctionTypeLambda extends TypeLambda { * @param input - The value to test. * * @example + * ```ts * import { isFunction } from "effect/Predicate" * * assert.deepStrictEqual(isFunction(isFunction), true) * assert.deepStrictEqual(isFunction("function"), false) + * ``` * * @category guards * @since 2.0.0 @@ -46,6 +48,7 @@ export const isFunction = (input: unknown): input is Function => typeof input == * @param body - The definition of the uncurried function. * * @example + * ```ts * import { dual, pipe } from "effect/Function" * * // Exampe using arity to determine data-first or data-last style @@ -65,6 +68,7 @@ export const isFunction = (input: unknown): input is Function => typeof input == * * assert.deepStrictEqual(sum(2, 3), 5) * assert.deepStrictEqual(pipe(2, sum(3)), 5) + * ``` * * @since 2.0.0 */ @@ -153,10 +157,12 @@ export const dual: { * @param self - The function to be applied to a value. * * @example + * ```ts * import { pipe, apply } from "effect/Function" * import { length } from "effect/String" * * assert.deepStrictEqual(pipe(length, apply("hello")), 5) + * ``` * * @since 2.0.0 */ @@ -166,9 +172,11 @@ export const apply = (a: A) => (self: (a: A) => B): B => self(a) * A lazy argument. * * @example + * ```ts * import { LazyArg, constant } from "effect/Function" * * const constNull: LazyArg = constant(null) + * ``` * * @since 2.0.0 */ @@ -178,9 +186,11 @@ export interface LazyArg { /** * @example + * ```ts * import { FunctionN } from "effect/Function" * * const sum: FunctionN<[number, number], number> = (a, b) => a + b + * ``` * * @since 2.0.0 */ @@ -194,9 +204,11 @@ export interface FunctionN, B> { * @param a - The input argument. * * @example + * ```ts * import { identity } from "effect/Function" * * assert.deepStrictEqual(identity(5), 5) + * ``` * * @since 2.0.0 */ @@ -207,6 +219,7 @@ export const identity = (a: A): A => a * without changing the resulting type of that expression. * * @example + * ```ts * import { satisfies } from "effect/Function" * * const test1 = satisfies()(5 as const) @@ -216,6 +229,7 @@ export const identity = (a: A): A => a * //^? Argument of type 'number' is not assignable to parameter of type 'string' * * assert.deepStrictEqual(satisfies()(5), 5) + * ``` * * @since 2.0.0 */ @@ -227,9 +241,11 @@ export const satisfies = () => (b: B) => b * @param a - The value to be casted to the target type. * * @example + * ```ts * import { unsafeCoerce, identity } from "effect/Function" * * assert.deepStrictEqual(unsafeCoerce, identity) + * ``` * * @since 2.0.0 */ @@ -244,12 +260,14 @@ export const unsafeCoerce: (a: A) => B = identity as any * @param value - The constant value to be returned. * * @example + * ```ts * import { constant } from "effect/Function" * * const constNull = constant(null) * * assert.deepStrictEqual(constNull(), null) * assert.deepStrictEqual(constNull(), null) + * ``` * * @since 2.0.0 */ @@ -259,9 +277,11 @@ export const constant = (value: A): LazyArg => () => value * A thunk that returns always `true`. * * @example + * ```ts * import { constTrue } from "effect/Function" * * assert.deepStrictEqual(constTrue(), true) + * ``` * * @since 2.0.0 */ @@ -271,9 +291,11 @@ export const constTrue: LazyArg = constant(true) * A thunk that returns always `false`. * * @example + * ```ts * import { constFalse } from "effect/Function" * * assert.deepStrictEqual(constFalse(), false) + * ``` * * @since 2.0.0 */ @@ -283,9 +305,11 @@ export const constFalse: LazyArg = constant(false) * A thunk that returns always `null`. * * @example + * ```ts * import { constNull } from "effect/Function" * * assert.deepStrictEqual(constNull(), null) + * ``` * * @since 2.0.0 */ @@ -295,9 +319,11 @@ export const constNull: LazyArg = constant(null) * A thunk that returns always `undefined`. * * @example + * ```ts * import { constUndefined } from "effect/Function" * * assert.deepStrictEqual(constUndefined(), undefined) + * ``` * * @since 2.0.0 */ @@ -307,9 +333,11 @@ export const constUndefined: LazyArg = constant(undefined) * A thunk that returns always `void`. * * @example + * ```ts * import { constVoid } from "effect/Function" * * assert.deepStrictEqual(constVoid(), undefined) + * ``` * * @since 2.0.0 */ @@ -321,11 +349,13 @@ export const constVoid: LazyArg = constUndefined * @param f - A curried function that takes multiple arguments. * * @example + * ```ts * import { flip } from "effect/Function" * * const f = (a: number) => (b: string) => a - b.length * * assert.deepStrictEqual(flip(f)('aaa')(2), -1) + * ``` * * @since 2.0.0 */ @@ -343,12 +373,14 @@ export const flip = , B extends Array, C>( * @param bc - A function that maps from `B` to `C`. * * @example + * ```ts * import { compose } from "effect/Function" * * const increment = (n: number) => n + 1; * const square = (n: number) => n * n; * * assert.strictEqual(compose(increment, square)(2), 9); + * ``` * * @since 2.0.0 */ @@ -373,11 +405,13 @@ export const absurd = (_: never): A => { * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument. * * @example + * ```ts * import { tupled } from "effect/Function" * * const sumTupled = tupled((x: number, y: number): number => x + y) * * assert.deepStrictEqual(sumTupled([1, 2]), 3) + * ``` * * @since 2.0.0 */ @@ -387,11 +421,13 @@ export const tupled = , B>(f: (...a: A) => B): * Inverse function of `tupled` * * @example + * ```ts * import { untupled } from "effect/Function" * * const getFirst = untupled((tuple: [A, B]): A => tuple[0]) * * assert.deepStrictEqual(getFirst(1, 2), 1) + * ``` * * @since 2.0.0 */ @@ -447,6 +483,7 @@ export const untupled = , B>(f: (a: A) => B): ( * argument** because they are only called with a single argument. * * @example + * ```ts * // Example: Chaining Arithmetic Operations * import { pipe } from "effect" * @@ -460,6 +497,7 @@ export const untupled = , B>(f: (a: A) => B): ( * * console.log(result) * // Output: 2 + * ``` * * @since 2.0.0 */ @@ -957,6 +995,7 @@ export function pipe( * See also [`pipe`](#pipe). * * @example + * ```ts * import { flow } from "effect/Function" * * const len = (s: string): number => s.length @@ -965,6 +1004,7 @@ export function pipe( * const f = flow(len, double) * * assert.strictEqual(f('aaa'), 6) + * ``` * * @since 2.0.0 */ @@ -1150,9 +1190,11 @@ export const hole: () => T = unsafeCoerce(absurd) * @param b - The second argument to be returned. * * @example + * ```ts * import { SK } from "effect/Function"; * * assert.deepStrictEqual(SK(0, "hello"), "hello") + * ``` * * @since 2.0.0 */ diff --git a/packages/effect/src/GlobalValue.ts b/packages/effect/src/GlobalValue.ts index a7cc5b0b924..7308a15584f 100644 --- a/packages/effect/src/GlobalValue.ts +++ b/packages/effect/src/GlobalValue.ts @@ -32,6 +32,7 @@ const globalStore = (globalThis as any)[globalStoreId] as Map * thereafter. * * @example + * ```ts * import { globalValue } from "effect/GlobalValue" * * // This cache will persist as long as the module is running, @@ -40,6 +41,7 @@ const globalStore = (globalThis as any)[globalStoreId] as Map * Symbol.for("myCache"), * () => new WeakMap() * ) + * ``` * * @since 2.0.0 */ diff --git a/packages/effect/src/HashMap.ts b/packages/effect/src/HashMap.ts index f5a881f727c..fa0cb9ac7b8 100644 --- a/packages/effect/src/HashMap.ts +++ b/packages/effect/src/HashMap.ts @@ -40,6 +40,7 @@ export declare namespace HashMap { * This type-level utility extracts the key type `K` from a `HashMap` type. * * @example + * ```ts * import { HashMap } from "effect" * * declare const hm: HashMap.HashMap @@ -47,6 +48,7 @@ export declare namespace HashMap { * // $ExpectType string * type K = HashMap.HashMap.Key * + * ``` * @since 2.0.0 * @category type-level */ @@ -55,6 +57,7 @@ export declare namespace HashMap { * This type-level utility extracts the value type `V` from a `HashMap` type. * * @example + * ```ts * import { HashMap } from "effect" * * declare const hm: HashMap.HashMap @@ -62,6 +65,7 @@ export declare namespace HashMap { * // $ExpectType number * type V = HashMap.HashMap.Value * + * ``` * @since 2.0.0 * @category type-level */ @@ -71,6 +75,7 @@ export declare namespace HashMap { * This type-level utility extracts the entry type `[K, V]` from a `HashMap` type. * * @example + * ```ts * import { HashMap } from "effect" * * declare const hm: HashMap.HashMap @@ -78,6 +83,7 @@ export declare namespace HashMap { * // $ExpectType [string, number] * type V = HashMap.HashMap.Entry * + * ``` * @since 3.9.0 * @category type-level */ diff --git a/packages/effect/src/Iterable.ts b/packages/effect/src/Iterable.ts index 3a75e057dd9..81f197d1950 100644 --- a/packages/effect/src/Iterable.ts +++ b/packages/effect/src/Iterable.ts @@ -24,9 +24,11 @@ import type { NoInfer } from "./Types.js" * **Note**. `length` is normalized to an integer >= 1. * * @example + * ```ts * import { makeBy } from "effect/Iterable" * * assert.deepStrictEqual(Array.from(makeBy(n => n * 2, { length: 5 })), [0, 2, 4, 6, 8]) + * ``` * * @category constructors * @since 2.0.0 @@ -56,9 +58,11 @@ export const makeBy = (f: (i: number) => A, options?: { * If `end` is omitted, the range will not have an upper bound. * * @example + * ```ts * import { range } from "effect/Iterable" * * assert.deepStrictEqual(Array.from(range(1, 3)), [1, 2, 3]) + * ``` * * @category constructors * @since 2.0.0 @@ -78,9 +82,11 @@ export const range = (start: number, end?: number): Iterable => { * **Note**. `n` is normalized to an integer >= 1. * * @example + * ```ts * import { replicate } from "effect/Iterable" * * assert.deepStrictEqual(Array.from(replicate("a", 3)), ["a", "a", "a"]) + * ``` * * @category constructors * @since 2.0.0 @@ -96,10 +102,12 @@ export const replicate: { * @param self - The record to transform. * * @example + * ```ts * import { fromRecord } from "effect/Iterable" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(Array.from(fromRecord(x)), [["a", 1], ["b", 2], ["c", 3]]) + * ``` * * @category conversions * @since 2.0.0 @@ -129,12 +137,14 @@ export const prepend: { * Prepends the specified prefix iterable to the beginning of the specified iterable. * * @example + * ```ts * import { Iterable } from "effect" * * assert.deepStrictEqual( * Array.from(Iterable.prependAll([1, 2], ["a", "b"])), * ["a", "b", 1, 2] * ) + * ``` * * @category concatenating * @since 2.0.0 @@ -225,10 +235,12 @@ export const scan: { * Determine if an `Iterable` is empty * * @example + * ```ts * import { isEmpty } from "effect/Iterable" * * assert.deepStrictEqual(isEmpty([]), true); * assert.deepStrictEqual(isEmpty([1, 2, 3]), false); + * ``` * * @category guards * @since 2.0.0 @@ -819,12 +831,14 @@ export const filterMapWhile: { * Retrieves the `Some` values from an `Iterable` of `Option`s. * * @example + * ```ts * import { Iterable, Option } from "effect" * * assert.deepStrictEqual( * Array.from(Iterable.getSomes([Option.some(1), Option.none(), Option.some(2)])), * [1, 2] * ) + * ``` * * @category filtering * @since 2.0.0 @@ -835,12 +849,14 @@ export const getSomes: (self: Iterable>) => Iterable = filterMap * Retrieves the `Left` values from an `Iterable` of `Either`s. * * @example + * ```ts * import { Iterable, Either } from "effect" * * assert.deepStrictEqual( * Array.from(Iterable.getLefts([Either.right(1), Either.left("err"), Either.right(2)])), * ["err"] * ) + * ``` * * @category filtering * @since 2.0.0 @@ -851,12 +867,14 @@ export const getLefts = (self: Iterable>): Iterable => fil * Retrieves the `Right` values from an `Iterable` of `Either`s. * * @example + * ```ts * import { Iterable, Either } from "effect" * * assert.deepStrictEqual( * Array.from(Iterable.getRights([Either.right(1), Either.left("err"), Either.right(2)])), * [1, 2] * ) + * ``` * * @category filtering * @since 2.0.0 diff --git a/packages/effect/src/List.ts b/packages/effect/src/List.ts index af65300bdb0..0ff771622cd 100644 --- a/packages/effect/src/List.ts +++ b/packages/effect/src/List.ts @@ -325,12 +325,14 @@ export const append: { * If either list is non-empty, the result is also a non-empty list. * * @example + * ```ts * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.appendAll(List.make("a", "b")), List.toArray), * [1, 2, "a", "b"] * ) + * ``` * * @category concatenating * @since 2.0.0 @@ -358,12 +360,14 @@ export const prepend: { * If either list is non-empty, the result is also a non-empty list. * * @example + * ```ts * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.prependAll(List.make("a", "b")), List.toArray), * ["a", "b", 1, 2] * ) + * ``` * * @category concatenating * @since 2.0.0 diff --git a/packages/effect/src/Logger.ts b/packages/effect/src/Logger.ts index 60a06251853..fbcea113825 100644 --- a/packages/effect/src/Logger.ts +++ b/packages/effect/src/Logger.ts @@ -77,6 +77,7 @@ export declare namespace Logger { * function. * * @example + * ```ts * import { Effect, Logger, LogLevel } from "effect" * * const logger = Logger.make(({ logLevel, message }) => { @@ -101,6 +102,7 @@ export declare namespace Logger { * // [DEBUG] task1 done * // [DEBUG] task2 done * // [INFO] done + * ``` * * @category constructors * @since 2.0.0 @@ -195,6 +197,7 @@ export const map: { * @param window - The time window in which to batch log messages. * * @example + * ```ts * import { Console, Effect, Logger } from "effect" * * const LoggerLive = Logger.replaceScoped( @@ -216,6 +219,7 @@ export const map: { * // timestamp=... level=INFO fiber=#0 message=two * // timestamp=... level=INFO fiber=#0 message=three * // ] + * ``` * * @since 2.0.0 * @category mapping @@ -243,6 +247,7 @@ export const withConsoleLog: (self: Logger) => Logger = fib * based on the log level. * * @example + * ```ts * import { Logger, Effect } from "effect" * * const loggerLayer = Logger.replace( @@ -254,6 +259,7 @@ export const withConsoleLog: (self: Logger) => Logger = fib * yield* Effect.logError("an error") * yield* Effect.logInfo("an info") * }).pipe(Effect.provide(loggerLayer)) + * ``` * * @since 3.8.0 * @category console @@ -344,12 +350,14 @@ export const test: { * control over which log messages are displayed based on their severity. * * @example + * ```ts * import { Effect, Logger, LogLevel } from "effect" * * const program = Effect.logDebug("message1").pipe(Logger.withMinimumLogLevel(LogLevel.Debug)) * * // Effect.runFork(program) * // timestamp=... level=DEBUG fiber=#0 message=message1 + * ``` * * @since 2.0.0 * @category context @@ -422,6 +430,7 @@ export const defaultLogger: Logger = fiberRuntime.defaultLogger * integrate with logging systems that consume JSON data. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -431,6 +440,7 @@ export const defaultLogger: Logger = fiberRuntime.defaultLogger * * // Effect.runFork(program.pipe(Effect.provide(Logger.json))) * // {"message":["message1","message2"],"logLevel":"INFO","timestamp":"...","annotations":{"key2":"value2","key1":"value1"},"spans":{"myspan":0},"fiberId":"#0"} + * ``` * * @since 2.0.0 * @category constructors @@ -442,6 +452,7 @@ export const jsonLogger: Logger = internal.jsonLogger * during development or in a production console. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -451,6 +462,7 @@ export const jsonLogger: Logger = internal.jsonLogger * * // Effect.runFork(program.pipe(Effect.provide(Logger.logFmt))) * // timestamp=... level=INFO fiber=#0 message=message1 message=message2 myspan=0ms key2=value2 key1=value1 + * ``` * * @since 2.0.0 * @category constructors @@ -470,6 +482,7 @@ export const stringLogger: Logger = internal.stringLogger * development and debugging processes. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -484,6 +497,7 @@ export const stringLogger: Logger = internal.stringLogger * // v-- bold * // key2: value2 * // key1: value1 + * ``` * * @since 3.5.0 * @category constructors @@ -511,6 +525,7 @@ export const prettyLoggerDefault: Logger = internal.prettyLoggerD * analysis and troubleshooting. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -528,6 +543,7 @@ export const prettyLoggerDefault: Logger = internal.prettyLoggerD * // spans: { myspan: 0 }, * // fiberId: '#0' * // } + * ``` * * @since 2.0.0 * @category constructors @@ -556,6 +572,7 @@ export const tracerLogger: Logger = fiberRuntime.tracerLogger * integrate with logging systems that consume JSON data. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -565,6 +582,7 @@ export const tracerLogger: Logger = fiberRuntime.tracerLogger * * // Effect.runFork(program.pipe(Effect.provide(Logger.json))) * // {"message":["message1","message2"],"logLevel":"INFO","timestamp":"...","annotations":{"key2":"value2","key1":"value1"},"spans":{"myspan":0},"fiberId":"#0"} + * ``` * * @since 2.0.0 * @category constructors @@ -576,6 +594,7 @@ export const json: Layer.Layer = replace(fiberRuntime.defaultLogger, fibe * during development or in a production console. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -585,6 +604,7 @@ export const json: Layer.Layer = replace(fiberRuntime.defaultLogger, fibe * * // Effect.runFork(program.pipe(Effect.provide(Logger.logFmt))) * // timestamp=... level=INFO fiber=#0 message=message1 message=message2 myspan=0ms key2=value2 key1=value1 + * ``` * * @since 2.0.0 * @category constructors @@ -598,6 +618,7 @@ export const logFmt: Layer.Layer = replace(fiberRuntime.defaultLogger, fi * development and debugging processes. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -612,6 +633,7 @@ export const logFmt: Layer.Layer = replace(fiberRuntime.defaultLogger, fi * // v-- bold * // key2: value2 * // key1: value1 + * ``` * * @since 3.5.0 * @category constructors @@ -624,6 +646,7 @@ export const pretty: Layer.Layer = replace(fiberRuntime.defaultLogger, fi * analysis and troubleshooting. * * @example + * ```ts * import { Effect, Logger } from "effect" * * const program = Effect.log("message1", "message2").pipe( @@ -641,6 +664,7 @@ export const pretty: Layer.Layer = replace(fiberRuntime.defaultLogger, fi * // spans: { myspan: 0 }, * // fiberId: '#0' * // } + * ``` * * @since 2.0.0 * @category constructors @@ -652,6 +676,7 @@ export const structured: Layer.Layer = replace(fiberRuntime.defaultLogger * which log messages are displayed based on their severity. * * @example + * ```ts * import { Effect, Logger, LogLevel } from "effect" * * const program = Effect.gen(function*() { @@ -663,6 +688,7 @@ export const structured: Layer.Layer = replace(fiberRuntime.defaultLogger * // Logging disabled using a layer * // Effect.runFork(program.pipe(Effect.provide(Logger.minimumLogLevel(LogLevel.None)))) * // task done + * ``` * * @since 2.0.0 * @category context diff --git a/packages/effect/src/Mailbox.ts b/packages/effect/src/Mailbox.ts index 41a69976af3..d2d71b29bbd 100644 --- a/packages/effect/src/Mailbox.ts +++ b/packages/effect/src/Mailbox.ts @@ -178,6 +178,7 @@ export interface ReadonlyMailbox * @experimental * @category constructors * @example + * ```ts * import { Effect, Mailbox } from "effect" * * Effect.gen(function*() { @@ -202,6 +203,7 @@ export interface ReadonlyMailbox * // signal that the mailbox has failed * yield* mailbox.fail("boom") * }) + * ``` */ export const make: ( capacity?: number | { diff --git a/packages/effect/src/ManagedRuntime.ts b/packages/effect/src/ManagedRuntime.ts index 0ab054c5dbe..f5f3415380c 100644 --- a/packages/effect/src/ManagedRuntime.ts +++ b/packages/effect/src/ManagedRuntime.ts @@ -156,6 +156,7 @@ export interface ManagedRuntimeUnifyIgnore extends Effect.EffectUnifyIgnore { * @since 2.0.0 * @category runtime class * @example + * ```ts * import { Console, Effect, Layer, ManagedRuntime } from "effect" * * class Notifications extends Effect.Tag("Notifications")< @@ -172,6 +173,7 @@ export interface ManagedRuntimeUnifyIgnore extends Effect.EffectUnifyIgnore { * } * * main() + * ``` */ export const make: ( layer: Layer.Layer, diff --git a/packages/effect/src/Metric.ts b/packages/effect/src/Metric.ts index 34cb8dc3752..d8a63328e34 100644 --- a/packages/effect/src/Metric.ts +++ b/packages/effect/src/Metric.ts @@ -167,6 +167,7 @@ export const mapInput: { * - incremental - Set to 'true' for a counter that only increases. With this configuration, Effect ensures that non-incremental updates have no impact on the counter, making it exclusively suitable for counting upwards. * * @example + * ```ts * import { Metric } from "effect" * * const numberCounter = Metric.counter("count", { @@ -177,6 +178,7 @@ export const mapInput: { * description: "A bigint counter", * bigint: true * }); + * ``` * * @since 2.0.0 * @category constructors @@ -208,11 +210,13 @@ export const counter: { * @param description - An optional description of the Frequency metric. * * @example + * ```ts * import { Metric } from "effect" * * const errorFrequency = Metric.frequency("error_frequency", { * description: "Counts the occurrences of errors." * }); + * ``` * * @since 2.0.0 * @category constructors @@ -256,6 +260,7 @@ export const fromMetricKey: > * - bigint - Indicates if the counter uses 'bigint' data type. * * @example + * ```ts * import { Metric } from "effect" * * const numberGauge = Metric.gauge("memory_usage", { @@ -266,6 +271,7 @@ export const fromMetricKey: > * description: "A gauge for CPU load", * bigint: true * }); + * ``` * * @since 2.0.0 * @category constructors @@ -290,12 +296,14 @@ export const gauge: { * @param description - A description of the histogram metric. * * @example + * ```ts * import { Metric, MetricBoundaries } from "effect" * * const latencyHistogram = Metric.histogram("latency_histogram", * MetricBoundaries.linear({ start: 0, width: 10, count: 11 }), * "Measures the distribution of request latency." * ); + * ``` * * @since 2.0.0 * @category constructors @@ -408,6 +416,7 @@ export const sync: (evaluate: LazyArg) => Metric = * - description - An optional description of the Summary metric. * * @example + * ```ts * import { Metric, Chunk } from "effect" * * const responseTimesSummary = Metric.summary({ @@ -418,6 +427,7 @@ export const sync: (evaluate: LazyArg) => Metric = * quantiles: [0.5, 0.9, 0.99], // Calculate 50th, 90th, and 99th percentiles. * description: "Measures the distribution of response times." * }); + * ``` * * @since 2.0.0 * @category constructors diff --git a/packages/effect/src/Micro.ts b/packages/effect/src/Micro.ts index 8c0f6284e05..6e5e7a8f017 100644 --- a/packages/effect/src/Micro.ts +++ b/packages/effect/src/Micro.ts @@ -986,6 +986,7 @@ export const currentScheduler: EnvRef = envRefMake( * @experimental * @category environment refs * @example + * ```ts * import * as Micro from "effect/Micro" * * Micro.forEach([1, 2, 3], (n) => Micro.succeed(n), { @@ -993,6 +994,7 @@ export const currentScheduler: EnvRef = envRefMake( * }).pipe( * Micro.withConcurrency(2) // use a concurrency of 2 * ) + * ``` */ export const withConcurrency: { (concurrency: "unbounded" | number): (self: Micro) => Micro @@ -1301,12 +1303,14 @@ export { * @experimental * @category constructors * @example + * ```ts * import { Micro } from "effect" * * Micro.try({ * try: () => throw new Error("boom"), * catch: (cause) => new Error("caught", { cause }) * }) + * ``` */ try_ as try } @@ -1335,12 +1339,14 @@ export const promise = (evaluate: (signal: AbortSignal) => PromiseLike): M * @experimental * @category constructors * @example + * ```ts * import { Micro } from "effect" * * Micro.tryPromise({ * try: () => Promise.resolve("success"), * catch: (cause) => new Error("caught", { cause }) * }) + * ``` */ export const tryPromise = (options: { readonly try: (signal: AbortSignal) => PromiseLike @@ -3321,6 +3327,7 @@ export const uninterruptible = (self: Micro): Micro = * @experimental * @category interruption * @example + * ```ts * import * as Micro from "effect/Micro" * * Micro.uninterruptibleMask((restore) => @@ -3328,6 +3335,7 @@ export const uninterruptible = (self: Micro): Micro = * Micro.andThen(restore(Micro.sleep(1000))) // interruptible * ) * ) + * ``` */ export const uninterruptibleMask = ( f: (restore: (effect: Micro) => Micro) => Micro @@ -3947,6 +3955,7 @@ export const forkScoped = (self: Micro): Micro, n * @experimental * @category execution * @example + * ```ts * import * as Micro from "effect/Micro" * * const handle = Micro.succeed(42).pipe( @@ -3957,6 +3966,7 @@ export const forkScoped = (self: Micro): Micro, n * handle.addObserver((exit) => { * console.log(exit) * }) + * ``` */ export const runFork = ( effect: Micro, diff --git a/packages/effect/src/Number.ts b/packages/effect/src/Number.ts index ad5ea1a8e66..4ad347f469d 100644 --- a/packages/effect/src/Number.ts +++ b/packages/effect/src/Number.ts @@ -19,10 +19,12 @@ import * as predicate from "./Predicate.js" * @param input - The value to test. * * @example + * ```ts * import { isNumber } from "effect/Number" * * assert.deepStrictEqual(isNumber(2), true) * assert.deepStrictEqual(isNumber("2"), false) + * ``` * * @category guards * @since 2.0.0 @@ -36,9 +38,11 @@ export const isNumber: (input: unknown) => input is number = predicate.isNumber * @param that - The second operand. * * @example + * ```ts * import { sum } from "effect/Number" * * assert.deepStrictEqual(sum(2, 3), 5) + * ``` * * @category math * @since 2.0.0 @@ -55,9 +59,11 @@ export const sum: { * @param that - The second operand. * * @example + * ```ts * import { multiply } from "effect/Number" * * assert.deepStrictEqual(multiply(2, 3), 6) + * ``` * * @category math * @since 2.0.0 @@ -74,9 +80,11 @@ export const multiply: { * @param that - The second operand. * * @example + * ```ts * import { subtract } from "effect/Number" * * assert.deepStrictEqual(subtract(2, 3), -1) + * ``` * * @category math * @since 2.0.0 @@ -93,10 +101,12 @@ export const subtract: { * @param that - The divisor operand. * * @example + * ```ts * import { Number, Option } from "effect" * * assert.deepStrictEqual(Number.divide(6, 3), Option.some(2)) * assert.deepStrictEqual(Number.divide(6, 0), Option.none()) + * ``` * * @category math * @since 2.0.0 @@ -118,9 +128,11 @@ export const divide: { * @param that - The divisor operand. * * @example + * ```ts * import { unsafeDivide } from "effect/Number" * * assert.deepStrictEqual(unsafeDivide(6, 3), 2) + * ``` * * @category math * @since 2.0.0 @@ -136,9 +148,11 @@ export const unsafeDivide: { * @param n - A `number` to be incremented. * * @example + * ```ts * import { increment } from "effect/Number" * * assert.deepStrictEqual(increment(2), 3) + * ``` * * @category math * @since 2.0.0 @@ -151,9 +165,11 @@ export const increment = (n: number): number => n + 1 * @param n - A `number` to be decremented. * * @example + * ```ts * import { decrement } from "effect/Number" * * assert.deepStrictEqual(decrement(3), 2) + * ``` * * @category math * @since 2.0.0 @@ -179,11 +195,13 @@ export const Order: order.Order = order.number * @param that - The second argument. * * @example + * ```ts * import { lessThan } from "effect/Number" * * assert.deepStrictEqual(lessThan(2, 3), true) * assert.deepStrictEqual(lessThan(3, 3), false) * assert.deepStrictEqual(lessThan(4, 3), false) + * ``` * * @category predicates * @since 2.0.0 @@ -200,11 +218,13 @@ export const lessThan: { * @param that - The second `number` to compare with. * * @example + * ```ts * import { lessThanOrEqualTo } from "effect/Number" * * assert.deepStrictEqual(lessThanOrEqualTo(2, 3), true) * assert.deepStrictEqual(lessThanOrEqualTo(3, 3), true) * assert.deepStrictEqual(lessThanOrEqualTo(4, 3), false) + * ``` * * @category predicates * @since 2.0.0 @@ -221,11 +241,13 @@ export const lessThanOrEqualTo: { * @param that - The second argument. * * @example + * ```ts * import { greaterThan } from "effect/Number" * * assert.deepStrictEqual(greaterThan(2, 3), false) * assert.deepStrictEqual(greaterThan(3, 3), false) * assert.deepStrictEqual(greaterThan(4, 3), true) + * ``` * * @category predicates * @since 2.0.0 @@ -242,11 +264,13 @@ export const greaterThan: { * @param that - The second `number` to compare with. * * @example + * ```ts * import { greaterThanOrEqualTo } from "effect/Number" * * assert.deepStrictEqual(greaterThanOrEqualTo(2, 3), false) * assert.deepStrictEqual(greaterThanOrEqualTo(3, 3), true) * assert.deepStrictEqual(greaterThanOrEqualTo(4, 3), true) + * ``` * * @category predicates * @since 2.0.0 @@ -264,6 +288,7 @@ export const greaterThanOrEqualTo: { * @param maximum - The `maximum` value to check. * * @example + * ```ts * import { Number } from "effect" * * const between = Number.between({ minimum: 0, maximum: 5 }) @@ -271,6 +296,7 @@ export const greaterThanOrEqualTo: { * assert.deepStrictEqual(between(3), true) * assert.deepStrictEqual(between(-1), false) * assert.deepStrictEqual(between(6), false) + * ``` * * @category predicates * @since 2.0.0 @@ -298,6 +324,7 @@ export const between: { * @param maximum - The upper end of the range. * * @example + * ```ts * import { Number } from "effect" * * const clamp = Number.clamp({ minimum: 1, maximum: 5 }) @@ -305,6 +332,7 @@ export const between: { * assert.equal(clamp(3), 3) * assert.equal(clamp(0), 1) * assert.equal(clamp(6), 5) + * ``` * * @since 2.0.0 */ @@ -326,9 +354,11 @@ export const clamp: { * @param that - The second `number`. * * @example + * ```ts * import { min } from "effect/Number" * * assert.deepStrictEqual(min(2, 3), 2) + * ``` * * @since 2.0.0 */ @@ -344,9 +374,11 @@ export const min: { * @param that - The second `number`. * * @example + * ```ts * import { max } from "effect/Number" * * assert.deepStrictEqual(max(2, 3), 3) + * ``` * * @since 2.0.0 */ @@ -361,11 +393,13 @@ export const max: { * @param n - The `number` to determine the sign of. * * @example + * ```ts * import { sign } from "effect/Number" * * assert.deepStrictEqual(sign(-5), -1) * assert.deepStrictEqual(sign(0), 0) * assert.deepStrictEqual(sign(5), 1) + * ``` * * @category math * @since 2.0.0 @@ -378,9 +412,11 @@ export const sign = (n: number): Ordering => Order(n, 0) * @param collection - The collection of `number`s to sum. * * @example + * ```ts * import { sumAll } from "effect/Number" * * assert.deepStrictEqual(sumAll([2, 3, 4]), 9) + * ``` * * @category math * @since 2.0.0 @@ -399,9 +435,11 @@ export const sumAll = (collection: Iterable): number => { * @param collection - The collection of `number`s to multiply. * * @example + * ```ts * import { multiplyAll } from "effect/Number" * * assert.deepStrictEqual(multiplyAll([2, 3, 4]), 24) + * ``` * * @category math * @since 2.0.0 @@ -426,11 +464,13 @@ export const multiplyAll = (collection: Iterable): number => { * @param divisor - The divisor. * * @example + * ```ts * import { remainder } from "effect/Number" * * assert.deepStrictEqual(remainder(2, 2), 0) * assert.deepStrictEqual(remainder(3, 2), 1) * assert.deepStrictEqual(remainder(-4, 2), -0) + * ``` * * @category math * @since 2.0.0 @@ -454,10 +494,12 @@ export const remainder: { * @param self - The number to find the next power of 2 from. * * @example + * ```ts * import { nextPow2 } from "effect/Number" * * assert.deepStrictEqual(nextPow2(5), 8) * assert.deepStrictEqual(nextPow2(17), 32) + * ``` * * @category math * @since 2.0.0 @@ -500,10 +542,12 @@ export const parse = (s: string): Option => { * @param precision - The precision * * @example + * ```ts * import { round } from "effect/Number" * * assert.deepStrictEqual(round(1.1234, 2), 1.12) * assert.deepStrictEqual(round(1.567, 2), 1.57) + * ``` * * @category math * @since 3.8.0 diff --git a/packages/effect/src/Option.ts b/packages/effect/src/Option.ts index f1323d78d9e..7ef0b24ea87 100644 --- a/packages/effect/src/Option.ts +++ b/packages/effect/src/Option.ts @@ -125,11 +125,13 @@ export const some: (value: A) => Option = option.some * @param input - The value to check. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.isOption(Option.some(1)), true) * assert.deepStrictEqual(Option.isOption(Option.none()), true) * assert.deepStrictEqual(Option.isOption({}), false) + * ``` * * @category guards * @since 2.0.0 @@ -142,10 +144,12 @@ export const isOption: (input: unknown) => input is Option = option.isO * @param self - The `Option` to check. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.isNone(Option.some(1)), false) * assert.deepStrictEqual(Option.isNone(Option.none()), true) + * ``` * * @category guards * @since 2.0.0 @@ -158,10 +162,12 @@ export const isNone: (self: Option) => self is None = option.isNone * @param self - The `Option` to check. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.isSome(Option.some(1)), true) * assert.deepStrictEqual(Option.isSome(Option.none()), false) + * ``` * * @category guards * @since 2.0.0 @@ -177,6 +183,7 @@ export const isSome: (self: Option) => self is Some = option.isSome * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned * * @example + * ```ts * import { pipe, Option } from "effect" * * assert.deepStrictEqual( @@ -188,6 +195,7 @@ export const isSome: (self: Option) => self is Some = option.isSome * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })), * 'a none' * ) + * ``` * * @category pattern matching * @since 2.0.0 @@ -214,6 +222,7 @@ export const match: { * This function ensures that a type guard definition is type-safe. * * @example + * ```ts * import { Option } from "effect" * * const parsePositive = (n: number): Option.Option => @@ -223,6 +232,7 @@ export const match: { * * assert.deepStrictEqual(isPositive(1), true) * assert.deepStrictEqual(isPositive(-1), false) + * ``` * * @category conversions * @since 2.0.0 @@ -236,10 +246,12 @@ export const toRefinement = (f: (a: A) => Option): (a: A) => * @param collection - The `Iterable` to be converted to an `Option`. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1)) * assert.deepStrictEqual(Option.fromIterable([]), Option.none()) + * ``` * * @category constructors * @since 2.0.0 @@ -255,10 +267,12 @@ export const fromIterable = (collection: Iterable): Option => { * Converts a `Either` to an `Option` discarding the error. * * @example + * ```ts * import { Option, Either } from "effect" * * assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok')) * assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none()) + * ``` * * @category conversions * @since 2.0.0 @@ -269,10 +283,12 @@ export const getRight: (self: Either) => Option = either.getRight * Converts a `Either` to an `Option` discarding the value. * * @example + * ```ts * import { Option, Either } from "effect" * * assert.deepStrictEqual(Option.getLeft(Either.right("ok")), Option.none()) * assert.deepStrictEqual(Option.getLeft(Either.left("a")), Option.some("a")) + * ``` * * @category conversions * @since 2.0.0 @@ -286,10 +302,12 @@ export const getLeft: (self: Either) => Option = either.getLeft * @param onNone - Function that returns the default value to return if the `Option` is `None`. * * @example + * ```ts * import { pipe, Option } from "effect" * * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1) * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0) + * ``` * * @category getters * @since 2.0.0 @@ -309,6 +327,7 @@ export const getOrElse: { * @param that - The `Option` to return if `self` is `None`. * * @example + * ```ts * import { pipe, Option } from "effect" * * assert.deepStrictEqual( @@ -339,6 +358,7 @@ export const getOrElse: { * ), * Option.some('a') * ) + * ``` * * @category error handling * @since 2.0.0 @@ -358,6 +378,7 @@ export const orElse: { * @param onNone - Function that returns the default value to return if the `Option` is `None`. * * @example + * ```ts * import { pipe, Option } from "effect" * * assert.deepStrictEqual( @@ -374,6 +395,7 @@ export const orElse: { * ), * Option.some('a') * ) + * ``` * * @category error handling * @since 2.0.0 @@ -413,9 +435,11 @@ export const orElseEither: { * @param collection - An iterable collection of `Option` to be searched. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1)) + * ``` * * @category error handling * @since 2.0.0 @@ -439,11 +463,13 @@ export const firstSomeOf = > = Iterable( * This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context. * * @example + * ```ts * import { Option } from "effect" * * const parse = (s: string): number | undefined => { @@ -469,6 +496,7 @@ export const fromNullable = ( * * assert.deepStrictEqual(parseOption('1'), Option.some(1)) * assert.deepStrictEqual(parseOption('not a number'), Option.none()) + * ``` * * @category conversions * @since 2.0.0 @@ -484,10 +512,12 @@ export const liftNullable = , B>( * @param self - The `Option` to extract the value from. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1) * assert.deepStrictEqual(Option.getOrNull(Option.none()), null) + * ``` * * @category getters * @since 2.0.0 @@ -500,10 +530,12 @@ export const getOrNull: (self: Option) => A | null = getOrElse(constNull) * @param self - The `Option` to extract the value from. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1) * assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined) + * ``` * * @category getters * @since 2.0.0 @@ -519,12 +551,14 @@ export const getOrUndefined: (self: Option) => A | undefined = getOrElse(c * @param f - the function that can throw exceptions. * * @example + * ```ts * import { Option } from "effect" * * const parse = Option.liftThrowable(JSON.parse) * * assert.deepStrictEqual(parse("1"), Option.some(1)) * assert.deepStrictEqual(parse(""), Option.none()) + * ``` * * @category conversions * @since 2.0.0 @@ -549,6 +583,7 @@ export const liftThrowable = , B>( * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual( @@ -556,6 +591,7 @@ export const liftThrowable = , B>( * 1 * ) * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None'))) + * ``` * * @category conversions * @since 2.0.0 @@ -579,10 +615,12 @@ export const getOrThrowWith: { * @throws `Error("getOrThrow called on a None")` * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1) * assert.throws(() => Option.getOrThrow(Option.none())) + * ``` * * @category conversions * @since 2.0.0 @@ -676,6 +714,7 @@ export const andThen: { * This is `flatMap` + `fromNullable`, useful when working with optional values. * * @example + * ```ts * import { pipe, Option } from "effect" * * interface Employee { @@ -707,6 +746,7 @@ export const andThen: { * ), * Option.none() * ) + * ``` * * @category sequencing * @since 2.0.0 @@ -770,6 +810,7 @@ export const zipLeft: { * @param self - The `Option` to apply the function to * * @example + * ```ts * import { Option } from "effect" * * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none() @@ -777,6 +818,7 @@ export const zipLeft: { * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none()) * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1)) * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none()) + * ``` * * @category sequencing * @since 2.0.0 @@ -824,11 +866,13 @@ export const productMany = ( * @param fields - the struct of `Option`s to be sequenced. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2])) * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some("hello") }), Option.some({ a: 1, b: "hello" })) * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none()) + * ``` * * @category combining * @since 2.0.0 @@ -873,6 +917,7 @@ export const all: > | Record> | Record`. * * @example + * ```ts * import { pipe, Option } from "effect" * * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()] * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3) + * ``` * * @category folding * @since 2.0.0 @@ -947,10 +995,12 @@ export const reduceCompact: { * @param self - The `Option` to convert to an array. * * @example + * ```ts * import { Option } from "effect" * * assert.deepStrictEqual(Option.toArray(Option.some(1)), [1]) * assert.deepStrictEqual(Option.toArray(Option.none()), []) + * ``` * * @category conversions * @since 2.0.0 @@ -984,6 +1034,7 @@ export const partitionMap: { * @param f - A function to apply to the value of the `Option`. * * @example + * ```ts * import { Option } from "effect" * * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none() @@ -991,6 +1042,7 @@ export const partitionMap: { * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none()) * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none()) * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2)) + * ``` * * @category filtering * @since 2.0.0 @@ -1012,6 +1064,7 @@ export const filterMap: { * @param fb - The `Option` to filter. * * @example + * ```ts * import { Option } from "effect" * * // predicate @@ -1027,6 +1080,7 @@ export const filterMap: { * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none()) * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none()) * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2)) + * ``` * * @category filtering * @since 2.0.0 @@ -1044,6 +1098,7 @@ export const filter: { /** * @example + * ```ts * import { Option, Number } from "effect" * * const isEquivalent = Option.getEquivalence(Number.Equivalence) @@ -1052,6 +1107,7 @@ export const filter: { * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false) * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false) * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true) + * ``` * * @category equivalence * @since 2.0.0 @@ -1067,6 +1123,7 @@ export const getEquivalence = (isEquivalent: Equivalence.Equivalence): Equ * `None` is considered to be less than any `Some` value. * * @example + * ```ts * import { pipe, Option, Number } from "effect" * * const O = Option.getOrder(Number.Order) @@ -1075,6 +1132,7 @@ export const getEquivalence = (isEquivalent: Equivalence.Equivalence): Equ * assert.deepStrictEqual(O(Option.some(1), Option.none()), 1) * assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1) * assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0) + * ``` * * @category sorting * @since 2.0.0 @@ -1102,12 +1160,14 @@ export const lift2 = (f: (a: A, b: B) => C): { * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean. * * @example + * ```ts * import { Option } from "effect" * * const getOption = Option.liftPredicate((n: number) => n >= 0) * * assert.deepStrictEqual(getOption(-1), Option.none()) * assert.deepStrictEqual(getOption(1), Option.some(1)) + * ``` * * @category lifting * @since 2.0.0 @@ -1136,11 +1196,13 @@ export const liftPredicate: { // Note: I intentionally avoid using the NoInfer p * @param a - The value to compare against the `Option`. * * @example + * ```ts * import { pipe, Option, Number } from "effect" * * assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true) * assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false) * assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false) + * ``` * * @category elements * @since 2.0.0 @@ -1170,6 +1232,7 @@ export const contains: { * @param predicate - The condition to check. * * @example + * ```ts * import { pipe, Option } from "effect" * * const isEven = (n: number) => n % 2 === 0 @@ -1177,6 +1240,7 @@ export const contains: { * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true) * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false) * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false) + * ``` * * @since 2.0.0 */ @@ -1211,6 +1275,7 @@ export const exists: { * @see {@link let_ let} * * @example + * ```ts * import { Option, pipe } from "effect" * * const result = pipe( @@ -1221,6 +1286,7 @@ export const exists: { * Option.filter(({ x, y }) => x * y > 5) * ) * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -1259,6 +1325,7 @@ export { * @see {@link bindTo} * * @example + * ```ts * import { Option, pipe } from "effect" * * const result = pipe( @@ -1270,6 +1337,7 @@ export { * ) * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 })) * + * ``` * @category do notation * @since 2.0.0 */ @@ -1292,6 +1360,7 @@ export { * @see {@link let_ let} * * @example + * ```ts * import { Option, pipe } from "effect" * * const result = pipe( @@ -1302,6 +1371,7 @@ export { * Option.filter(({ x, y }) => x * y > 5) * ) * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -1334,6 +1404,7 @@ export const bind: { * @see {@link let_ let} * * @example + * ```ts * import { Option, pipe } from "effect" * * const result = pipe( @@ -1344,6 +1415,7 @@ export const bind: { * Option.filter(({ x, y }) => x * y > 5) * ) * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 diff --git a/packages/effect/src/Order.ts b/packages/effect/src/Order.ts index f5449d14f9a..5f8a7139696 100644 --- a/packages/effect/src/Order.ts +++ b/packages/effect/src/Order.ts @@ -318,6 +318,7 @@ export const max = (O: Order): { * Clamp a value between a minimum and a maximum. * * @example + * ```ts * import { Order, Number } from "effect" * * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 }) @@ -325,6 +326,7 @@ export const max = (O: Order): { * assert.equal(clamp(3), 3) * assert.equal(clamp(0), 1) * assert.equal(clamp(6), 5) + * ``` * * @since 2.0.0 */ diff --git a/packages/effect/src/Ordering.ts b/packages/effect/src/Ordering.ts index 3dad7794a77..0d4dc6ec49d 100644 --- a/packages/effect/src/Ordering.ts +++ b/packages/effect/src/Ordering.ts @@ -16,11 +16,13 @@ export type Ordering = -1 | 0 | 1 * @param o - The input `Ordering`. * * @example + * ```ts * import { reverse } from "effect/Ordering" * * assert.deepStrictEqual(reverse(1), -1) * assert.deepStrictEqual(reverse(-1), 1) * assert.deepStrictEqual(reverse(0), 0) + * ``` * * @since 2.0.0 */ @@ -35,6 +37,7 @@ export const reverse = (o: Ordering): Ordering => (o === -1 ? 1 : o === 1 ? -1 : * @param onGreaterThan - A function that will be called if the `Ordering` parameter is `1`. * * @example + * ```ts * import { Ordering } from "effect" * import { constant } from "effect/Function" * @@ -47,6 +50,7 @@ export const reverse = (o: Ordering): Ordering => (o === -1 ? 1 : o === 1 ? -1 : * assert.deepStrictEqual(toMessage(-1), "less than") * assert.deepStrictEqual(toMessage(0), "equal") * assert.deepStrictEqual(toMessage(1), "greater than") + * ``` * * @category pattern matching * @since 2.0.0 diff --git a/packages/effect/src/Predicate.ts b/packages/effect/src/Predicate.ts index 523f095f2e1..1f93afc5e34 100644 --- a/packages/effect/src/Predicate.ts +++ b/packages/effect/src/Predicate.ts @@ -75,6 +75,7 @@ export declare namespace Refinement { * @param f - a function to transform `B` to `A`. * * @example + * ```ts * import { Predicate, Number } from "effect" * * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length) @@ -83,6 +84,7 @@ export declare namespace Refinement { * assert.deepStrictEqual(minLength3("aa"), false) * assert.deepStrictEqual(minLength3("aaa"), true) * assert.deepStrictEqual(minLength3("aaaa"), true) + * ``` * * @category combinators * @since 2.0.0 @@ -101,6 +103,7 @@ export const mapInput: { * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`. * * @example + * ```ts * import { isTupleOf } from "effect/Predicate" * * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true); @@ -112,6 +115,7 @@ export const mapInput: { * console.log(arr); * // ^? [number, number, number] * } + * ``` * * @category guards * @since 3.3.0 @@ -130,6 +134,7 @@ export const isTupleOf: { * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`. * * @example + * ```ts * import { isTupleOfAtLeast } from "effect/Predicate" * * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true); @@ -141,6 +146,7 @@ export const isTupleOf: { * console.log(arr); * // ^? [number, number, number, ...number[]] * } + * ``` * * @category guards * @since 3.3.0 @@ -156,11 +162,13 @@ export const isTupleOfAtLeast: { * @param input - The value to test. * * @example + * ```ts * import { isTruthy } from "effect/Predicate" * * assert.deepStrictEqual(isTruthy(1), true) * assert.deepStrictEqual(isTruthy(0), false) * assert.deepStrictEqual(isTruthy(""), false) + * ``` * * @category guards * @since 2.0.0 @@ -173,6 +181,7 @@ export const isTruthy = (input: unknown) => !!input * @param input - The value to test. * * @example + * ```ts * import { isSet } from "effect/Predicate" * * assert.deepStrictEqual(isSet(new Set([1, 2])), true) @@ -180,6 +189,7 @@ export const isTruthy = (input: unknown) => !!input * assert.deepStrictEqual(isSet({}), false) * assert.deepStrictEqual(isSet(null), false) * assert.deepStrictEqual(isSet(undefined), false) + * ``` * * @category guards * @since 2.0.0 @@ -192,12 +202,14 @@ export const isSet = (input: unknown): input is Set => input instanceof * @param input - The value to test. * * @example + * ```ts * import { isMap } from "effect/Predicate" * * assert.deepStrictEqual(isMap(new Map()), true) * assert.deepStrictEqual(isMap({}), false) * assert.deepStrictEqual(isMap(null), false) * assert.deepStrictEqual(isMap(undefined), false) + * ``` * * @category guards * @since 2.0.0 @@ -210,11 +222,13 @@ export const isMap = (input: unknown): input is Map => input i * @param input - The value to test. * * @example + * ```ts * import { isString } from "effect/Predicate" * * assert.deepStrictEqual(isString("a"), true) * * assert.deepStrictEqual(isString(1), false) + * ``` * * @category guards * @since 2.0.0 @@ -227,11 +241,13 @@ export const isString = (input: unknown): input is string => typeof input === "s * @param input - The value to test. * * @example + * ```ts * import { isNumber } from "effect/Predicate" * * assert.deepStrictEqual(isNumber(2), true) * * assert.deepStrictEqual(isNumber("2"), false) + * ``` * * @category guards * @since 2.0.0 @@ -244,11 +260,13 @@ export const isNumber = (input: unknown): input is number => typeof input === "n * @param input - The value to test. * * @example + * ```ts * import { isBoolean } from "effect/Predicate" * * assert.deepStrictEqual(isBoolean(true), true) * * assert.deepStrictEqual(isBoolean("true"), false) + * ``` * * @category guards * @since 2.0.0 @@ -261,11 +279,13 @@ export const isBoolean = (input: unknown): input is boolean => typeof input === * @param input - The value to test. * * @example + * ```ts * import { isBigInt } from "effect/Predicate" * * assert.deepStrictEqual(isBigInt(1n), true) * * assert.deepStrictEqual(isBigInt(1), false) + * ``` * * @category guards * @since 2.0.0 @@ -278,11 +298,13 @@ export const isBigInt = (input: unknown): input is bigint => typeof input === "b * @param input - The value to test. * * @example + * ```ts * import { isSymbol } from "effect/Predicate" * * assert.deepStrictEqual(isSymbol(Symbol.for("a")), true) * * assert.deepStrictEqual(isSymbol("a"), false) + * ``` * * @category guards * @since 2.0.0 @@ -295,11 +317,13 @@ export const isSymbol = (input: unknown): input is symbol => typeof input === "s * @param input - The value to test. * * @example + * ```ts * import { isFunction } from "effect/Predicate" * * assert.deepStrictEqual(isFunction(isFunction), true) * * assert.deepStrictEqual(isFunction("function"), false) + * ``` * * @category guards * @since 2.0.0 @@ -312,12 +336,14 @@ export const isFunction: (input: unknown) => input is Function = isFunction_ * @param input - The value to test. * * @example + * ```ts * import { isUndefined } from "effect/Predicate" * * assert.deepStrictEqual(isUndefined(undefined), true) * * assert.deepStrictEqual(isUndefined(null), false) * assert.deepStrictEqual(isUndefined("undefined"), false) + * ``` * * @category guards * @since 2.0.0 @@ -330,12 +356,14 @@ export const isUndefined = (input: unknown): input is undefined => input === und * @param input - The value to test. * * @example + * ```ts * import { isNotUndefined } from "effect/Predicate" * * assert.deepStrictEqual(isNotUndefined(null), true) * assert.deepStrictEqual(isNotUndefined("undefined"), true) * * assert.deepStrictEqual(isNotUndefined(undefined), false) + * ``` * * @category guards * @since 2.0.0 @@ -348,12 +376,14 @@ export const isNotUndefined = (input: A): input is Exclude => i * @param input - The value to test. * * @example + * ```ts * import { isNull } from "effect/Predicate" * * assert.deepStrictEqual(isNull(null), true) * * assert.deepStrictEqual(isNull(undefined), false) * assert.deepStrictEqual(isNull("null"), false) + * ``` * * @category guards * @since 2.0.0 @@ -366,12 +396,14 @@ export const isNull = (input: unknown): input is null => input === null * @param input - The value to test. * * @example + * ```ts * import { isNotNull } from "effect/Predicate" * * assert.deepStrictEqual(isNotNull(undefined), true) * assert.deepStrictEqual(isNotNull("null"), true) * * assert.deepStrictEqual(isNotNull(null), false) + * ``` * * @category guards * @since 2.0.0 @@ -384,12 +416,14 @@ export const isNotNull = (input: A): input is Exclude => input !== n * @param _ - The value to test. * * @example + * ```ts * import { isNever } from "effect/Predicate" * * assert.deepStrictEqual(isNever(null), false) * assert.deepStrictEqual(isNever(undefined), false) * assert.deepStrictEqual(isNever({}), false) * assert.deepStrictEqual(isNever([]), false) + * ``` * * @category guards * @since 2.0.0 @@ -402,6 +436,7 @@ export const isNever: (input: unknown) => input is never = (_: unknown): _ is ne * @param _ - The value to test. * * @example + * ```ts * import { isUnknown } from "effect/Predicate" * * assert.deepStrictEqual(isUnknown(null), true) @@ -409,6 +444,7 @@ export const isNever: (input: unknown) => input is never = (_: unknown): _ is ne * * assert.deepStrictEqual(isUnknown({}), true) * assert.deepStrictEqual(isUnknown([]), true) + * ``` * * @category guards * @since 2.0.0 @@ -425,6 +461,7 @@ export const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: un * @param input - The value to test. * * @example + * ```ts * import { isObject } from "effect/Predicate" * * assert.deepStrictEqual(isObject({}), true) @@ -432,6 +469,7 @@ export const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: un * * assert.deepStrictEqual(isObject(null), false) * assert.deepStrictEqual(isObject(undefined), false) + * ``` * * @category guards * @since 2.0.0 @@ -463,6 +501,7 @@ export const hasProperty: { * @param tag - The tag to test for. * * @example + * ```ts * import { isTagged } from "effect/Predicate" * * assert.deepStrictEqual(isTagged(1, "a"), false) @@ -471,6 +510,7 @@ export const hasProperty: { * assert.deepStrictEqual(isTagged({ a: "a" }, "a"), false) * assert.deepStrictEqual(isTagged({ _tag: "a" }, "a"), true) * assert.deepStrictEqual(isTagged("a")({ _tag: "a" }), true) + * ``` * * @category guards * @since 2.0.0 @@ -489,6 +529,7 @@ export const isTagged: { * @param input - The value to test. * * @example + * ```ts * import { isNullable } from "effect/Predicate" * * assert.deepStrictEqual(isNullable(null), true) @@ -496,6 +537,7 @@ export const isTagged: { * * assert.deepStrictEqual(isNullable({}), false) * assert.deepStrictEqual(isNullable([]), false) + * ``` * * @category guards * @since 2.0.0 @@ -508,6 +550,7 @@ export const isNullable = (input: A): input is Extract = * @param input - The value to test. * * @example + * ```ts * import { isNotNullable } from "effect/Predicate" * * assert.deepStrictEqual(isNotNullable({}), true) @@ -515,6 +558,7 @@ export const isNullable = (input: A): input is Extract = * * assert.deepStrictEqual(isNotNullable(null), false) * assert.deepStrictEqual(isNotNullable(undefined), false) + * ``` * * @category guards * @since 2.0.0 @@ -527,12 +571,14 @@ export const isNotNullable = (input: A): input is NonNullable => input !== * @param input - The value to test. * * @example + * ```ts * import { isError } from "effect/Predicate" * * assert.deepStrictEqual(isError(new Error()), true) * * assert.deepStrictEqual(isError(null), false) * assert.deepStrictEqual(isError({}), false) + * ``` * * @category guards * @since 2.0.0 @@ -545,12 +591,14 @@ export const isError = (input: unknown): input is Error => input instanceof Erro * @param input - The value to test. * * @example + * ```ts * import { isUint8Array } from "effect/Predicate" * * assert.deepStrictEqual(isUint8Array(new Uint8Array()), true) * * assert.deepStrictEqual(isUint8Array(null), false) * assert.deepStrictEqual(isUint8Array({}), false) + * ``` * * @category guards * @since 2.0.0 @@ -563,12 +611,14 @@ export const isUint8Array = (input: unknown): input is Uint8Array => input insta * @param input - The value to test. * * @example + * ```ts * import { isDate } from "effect/Predicate" * * assert.deepStrictEqual(isDate(new Date()), true) * * assert.deepStrictEqual(isDate(null), false) * assert.deepStrictEqual(isDate({}), false) + * ``` * * @category guards * @since 2.0.0 @@ -581,6 +631,7 @@ export const isDate = (input: unknown): input is Date => input instanceof Date * @param input - The value to test. * * @example + * ```ts * import { isIterable } from "effect/Predicate" * * assert.deepStrictEqual(isIterable([]), true) @@ -588,6 +639,7 @@ export const isDate = (input: unknown): input is Date => input instanceof Date * * assert.deepStrictEqual(isIterable(null), false) * assert.deepStrictEqual(isIterable({}), false) + * ``` * * @category guards * @since 2.0.0 @@ -600,6 +652,7 @@ export const isIterable = (input: unknown): input is Iterable => hasPro * @param input - The value to test. * * @example + * ```ts * import { isRecord } from "effect/Predicate" * * assert.deepStrictEqual(isRecord({}), true) @@ -610,6 +663,7 @@ export const isIterable = (input: unknown): input is Iterable => hasPro * assert.deepStrictEqual(isRecord(null), false) * assert.deepStrictEqual(isRecord(undefined), false) * assert.deepStrictEqual(isRecord(() => null), false) + * ``` * * @category guards * @since 2.0.0 @@ -623,6 +677,7 @@ export const isRecord = (input: unknown): input is { [x: string | symbol]: unkno * @param input - The value to test. * * @example + * ```ts * import { isReadonlyRecord } from "effect/Predicate" * * assert.deepStrictEqual(isReadonlyRecord({}), true) @@ -632,6 +687,7 @@ export const isRecord = (input: unknown): input is { [x: string | symbol]: unkno * assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false) * assert.deepStrictEqual(isReadonlyRecord(null), false) * assert.deepStrictEqual(isReadonlyRecord(undefined), false) + * ``` * * @category guards * @since 2.0.0 @@ -646,10 +702,12 @@ export const isReadonlyRecord: ( * @param input - The value to test. * * @example + * ```ts * import { isPromise } from "effect/Predicate" * * assert.deepStrictEqual(isPromise({}), false) * assert.deepStrictEqual(isPromise(Promise.resolve("hello")), true) + * ``` * * @category guards * @since 2.0.0 @@ -673,10 +731,12 @@ export const isPromiseLike = ( * @param input - The value to test. * * @example + * ```ts * import { Predicate } from "effect" * * assert.deepStrictEqual(Predicate.isRegExp(/a/), true) * assert.deepStrictEqual(Predicate.isRegExp("a"), false) + * ``` * * @category guards * @since 3.9.0 @@ -796,6 +856,7 @@ export const struct: { * @param self - A predicate. * * @example + * ```ts * import { Predicate, Number } from "effect" * * const isPositive = Predicate.not(Number.lessThan(0)) @@ -803,6 +864,7 @@ export const struct: { * assert.deepStrictEqual(isPositive(-1), false) * assert.deepStrictEqual(isPositive(0), true) * assert.deepStrictEqual(isPositive(1), true) + * ``` * * @category combinators * @since 2.0.0 @@ -816,6 +878,7 @@ export const not = (self: Predicate): Predicate => (a) => !self(a) * @param that - A predicate. * * @example + * ```ts * import { Predicate, Number } from "effect" * * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0)) @@ -823,6 +886,7 @@ export const not = (self: Predicate): Predicate => (a) => !self(a) * assert.deepStrictEqual(nonZero(-1), true) * assert.deepStrictEqual(nonZero(0), false) * assert.deepStrictEqual(nonZero(1), true) + * ``` * * @category combinators * @since 2.0.0 @@ -841,6 +905,7 @@ export const or: { * @param that - A predicate. * * @example + * ```ts * import { Predicate } from "effect" * * const minLength = (n: number) => (s: string) => s.length >= n @@ -851,6 +916,7 @@ export const or: { * assert.deepStrictEqual(length(2)("aa"), true) * assert.deepStrictEqual(length(2)("a"), false) * assert.deepStrictEqual(length(2)("aaa"), false) + * ``` * * @category combinators * @since 2.0.0 @@ -902,6 +968,7 @@ export const eqv: { * must be true. * * @example + * ```ts * import { Predicate } from "effect" * * type Triple = { @@ -920,6 +987,7 @@ export const eqv: { * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true) * // antecedent is `false`, so the result is `true` * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true) + * ``` * * @category combinators * @since 2.0.0 diff --git a/packages/effect/src/Random.ts b/packages/effect/src/Random.ts index 233a6f0f698..c74d1e17b06 100644 --- a/packages/effect/src/Random.ts +++ b/packages/effect/src/Random.ts @@ -110,12 +110,14 @@ export const shuffle: (elements: Iterable) => Effect.Effect * Get a random element from an iterable. * * @example + * ```ts * import { Effect, Random } from "effect" * * Effect.gen(function* () { * const randomItem = yield* Random.choice([1, 2, 3]) * console.log(randomItem) * }) + * ``` * * @since 3.6.0 * @category constructors @@ -155,12 +157,14 @@ export const Random: Context.Tag = internal.randomTag * @param seed - The seed value used to initialize the generator. * * @example + * ```ts * import { Effect, Random } from "effect" * * const random1 = Random.make("myseed") * const random2 = Random.make("myseed") * * assert.equal(Effect.runSync(random1.next), Effect.runSync(random2.next)) + * ``` * * @since 3.5.0 * @category constructors diff --git a/packages/effect/src/RateLimiter.ts b/packages/effect/src/RateLimiter.ts index ad476b89600..6d84e67e24f 100644 --- a/packages/effect/src/RateLimiter.ts +++ b/packages/effect/src/RateLimiter.ts @@ -70,6 +70,7 @@ export declare namespace RateLimiter { * - The "cost" per effect can be changed. See {@link withCost} * * @example + * ```ts * import { Effect, RateLimiter } from "effect"; * import { compose } from "effect/Function" * @@ -89,6 +90,7 @@ export declare namespace RateLimiter { * } * }) * ); + * ``` * * @since 2.0.0 * @category constructors @@ -103,6 +105,7 @@ export const make: (options: RateLimiter.Options) => Effect Effect( diff --git a/packages/effect/src/RcRef.ts b/packages/effect/src/RcRef.ts index e014272d9fe..b7dd9548468 100644 --- a/packages/effect/src/RcRef.ts +++ b/packages/effect/src/RcRef.ts @@ -77,6 +77,7 @@ export declare namespace RcRef { * @since 3.5.0 * @category constructors * @example + * ```ts * import { Effect, RcRef } from "effect" * * Effect.gen(function*() { @@ -94,6 +95,7 @@ export declare namespace RcRef { * Effect.scoped * ) * }) + * ``` */ export const make: ( options: { diff --git a/packages/effect/src/Record.ts b/packages/effect/src/Record.ts index 580a21b3477..cd382fea53e 100644 --- a/packages/effect/src/Record.ts +++ b/packages/effect/src/Record.ts @@ -69,10 +69,12 @@ export const empty = (): Record< * @param self - record to test for emptiness. * * @example + * ```ts * import { isEmptyRecord } from "effect/Record" * * assert.deepStrictEqual(isEmptyRecord({}), true); * assert.deepStrictEqual(isEmptyRecord({ a: 3 }), false); + * ``` * * @category guards * @since 2.0.0 @@ -86,10 +88,12 @@ export const isEmptyRecord = (self: Record): self is * @param self - record to test for emptiness. * * @example + * ```ts * import { isEmptyReadonlyRecord } from "effect/Record" * * assert.deepStrictEqual(isEmptyReadonlyRecord({}), true); * assert.deepStrictEqual(isEmptyReadonlyRecord({ a: 3 }), false); + * ``` * * @category guards * @since 2.0.0 @@ -106,6 +110,7 @@ export const isEmptyReadonlyRecord: ( * @param f - A projection function that maps values of the iterable to a tuple of a key and a value. * * @example + * ```ts * import { fromIterableWith } from "effect/Record" * * const input = [1, 2, 3, 4] @@ -114,6 +119,7 @@ export const isEmptyReadonlyRecord: ( * fromIterableWith(input, a => [String(a), a * 2]), * { '1': 2, '2': 4, '3': 6, '4': 8 } * ) + * ``` * * @category constructors * @since 2.0.0 @@ -148,6 +154,7 @@ export const fromIterableWith: { * @param f - A function that extracts the key for each element. * * @example + * ```ts * import { fromIterableBy } from "effect/Record" * * const users = [ @@ -162,6 +169,7 @@ export const fromIterableWith: { * "1": { id: "1", name: "name1" } * } * ) + * ``` * * @category constructors * @since 2.0.0 @@ -180,11 +188,13 @@ export const fromIterableBy = ( * @param self - The iterable of key-value pairs. * * @example + * ```ts * import { fromEntries } from "effect/Record" * * const input: Array<[string, number]> = [["a", 1], ["b", 2]] * * assert.deepStrictEqual(fromEntries(input), { a: 1, b: 2 }) + * ``` * * @since 2.0.0 * @category constructors @@ -200,10 +210,12 @@ export const fromEntries: ( * @param f - The custom mapping function to apply to each key/value of the record. * * @example + * ```ts * import { collect } from "effect/Record" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(collect(x, (key, n) => [key, n]), [["a", 1], ["b", 2], ["c", 3]]) + * ``` * * @category conversions * @since 2.0.0 @@ -228,10 +240,12 @@ export const collect: { * @param self - The record to transform. * * @example + * ```ts * import { toEntries } from "effect/Record" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(toEntries(x), [["a", 1], ["b", 2], ["c", 3]]) + * ``` * * @category conversions * @since 2.0.0 @@ -247,9 +261,11 @@ export const toEntries: (self: ReadonlyRecord) => Arr * @param self - A record to calculate the number of key/value pairs in. * * @example + * ```ts * import { size } from "effect/Record"; * * assert.deepStrictEqual(size({ a: "a", b: 1, c: true }), 3); + * ``` * * @since 2.0.0 */ @@ -262,10 +278,12 @@ export const size = (self: ReadonlyRecord): number => * @param key - the key to look for in the record. * * @example + * ```ts * import { empty, has } from "effect/Record" * * assert.deepStrictEqual(has({ a: 1, b: 2 }, "a"), true); * assert.deepStrictEqual(has(empty(), "c"), false); + * ``` * * @since 2.0.0 */ @@ -292,12 +310,14 @@ export const has: { * @param key - Key to retrieve from record. * * @example + * ```ts * import { Record as R, Option } from "effect" * * const person: Record = { name: "John Doe", age: 35 } * * assert.deepStrictEqual(R.get(person, "name"), Option.some("John Doe")) * assert.deepStrictEqual(R.get(person, "email"), Option.none()) + * ``` * * @since 2.0.0 */ @@ -319,6 +339,7 @@ export const get: { * @param f - The function to apply to the element. * * @example + * ```ts * import { Record as R } from "effect" * * const f = (x: number) => x * 2 @@ -331,6 +352,7 @@ export const get: { * R.modify({ a: 3 } as Record, 'b', f), * { a: 3 } * ) + * ``` * * @since 2.0.0 */ @@ -359,6 +381,7 @@ export const modify: { * @param f - The function to apply to the element. * * @example + * ```ts * import { Record as R, Option } from "effect" * * const f = (x: number) => x * 2 @@ -371,6 +394,7 @@ export const modify: { * R.modifyOption({ a: 3 } as Record, 'b', f), * Option.none() * ) + * ``` * * @since 2.0.0 */ @@ -406,6 +430,7 @@ export const modifyOption: { * @param b - The new value to replace the existing value with. * * @example + * ```ts * import { Record, Option } from "effect" * * assert.deepStrictEqual( @@ -413,6 +438,7 @@ export const modifyOption: { * Option.some({ a: 10, b: 2, c: 3 }) * ) * assert.deepStrictEqual(Record.replaceOption(Record.empty(), 'a', 10), Option.none()) + * ``` * * @since 2.0.0 */ @@ -443,9 +469,11 @@ export const replaceOption: { * @param key - the key to remove from the record. * * @example + * ```ts * import { remove } from "effect/Record" * * assert.deepStrictEqual(remove({ a: 1, b: 2 }, "a"), { b: 2 }) + * ``` * * @since 2.0.0 */ @@ -473,10 +501,12 @@ export const remove: { * @param key - The key of the property to retrieve. * * @example + * ```ts * import { Record as R, Option } from "effect" * * assert.deepStrictEqual(R.pop({ a: 1, b: 2 }, "a"), Option.some([1, { b: 2 }])) * assert.deepStrictEqual(R.pop({ a: 1, b: 2 } as Record, "c"), Option.none()) + * ``` * * @category record * @since 2.0.0 @@ -502,6 +532,7 @@ export const pop: { * @param f - A transformation function that will be applied to each of the values in the record. * * @example + * ```ts * import { map } from "effect/Record" * * const f = (n: number) => `-${n}` @@ -511,6 +542,7 @@ export const pop: { * const g = (n: number, key: string) => `${key.toUpperCase()}-${n}` * * assert.deepStrictEqual(map({ a: 3, b: 5 }, g), { a: "A-3", b: "B-5" }) + * ``` * * @category mapping * @since 2.0.0 @@ -533,9 +565,11 @@ export const map: { * Maps the keys of a `ReadonlyRecord` while preserving the corresponding values. * * @example + * ```ts * import { mapKeys } from "effect/Record" * * assert.deepStrictEqual(mapKeys({ a: 3, b: 5 }, (key) => key.toUpperCase()), { A: 3, B: 5 }) + * ``` * * @category mapping * @since 2.0.0 @@ -567,9 +601,11 @@ export const mapKeys: { * Maps entries of a `ReadonlyRecord` using the provided function, allowing modification of both keys and corresponding values. * * @example + * ```ts * import { mapEntries } from "effect/Record" * * assert.deepStrictEqual(mapEntries({ a: 3, b: 5 }, (a, key) => [key.toUpperCase(), a + 1]), { A: 4, B: 6 }) + * ``` * * @category mapping * @since 2.0.0 @@ -605,11 +641,13 @@ export const mapEntries: { * @param f - The transformation function. * * @example + * ```ts * import { Record, Option } from "effect" * * const x = { a: 1, b: 2, c: 3 } * const f = (a: number, key: string) => a > 2 ? Option.some(a * 2) : Option.none() * assert.deepStrictEqual(Record.filterMap(x, f), { c: 6 }) + * ``` * * @since 2.0.0 */ @@ -645,10 +683,12 @@ export const filterMap: { * @param predicate - A function that returns a `boolean` value to determine if the entry should be included in the new record. * * @example + * ```ts * import { filter } from "effect/Record" * * const x = { a: 1, b: 2, c: 3, d: 4 } * assert.deepStrictEqual(filter(x, (n) => n > 2), { c: 3, d: 4 }) + * ``` * * @category filtering * @since 2.0.0 @@ -690,12 +730,14 @@ export const filter: { * @param self - A record with `Option` values. * * @example + * ```ts * import { Record, Option } from "effect" * * assert.deepStrictEqual( * Record.getSomes({ a: Option.some(1), b: Option.none(), c: Option.some(2) }), * { a: 1, c: 2 } * ) + * ``` * * @category filtering * @since 2.0.0 @@ -710,12 +752,14 @@ export const getSomes: ( * Given a record with `Either` values, returns a new record containing only the `Left` values, preserving the original keys. * * @example + * ```ts * import { Record, Either } from "effect" * * assert.deepStrictEqual( * Record.getLefts({ a: Either.right(1), b: Either.left("err"), c: Either.right(2) }), * { b: "err" } * ) + * ``` * * @category filtering * @since 2.0.0 @@ -738,12 +782,14 @@ export const getLefts = ( * Given a record with `Either` values, returns a new record containing only the `Right` values, preserving the original keys. * * @example + * ```ts * import { Record, Either } from "effect" * * assert.deepStrictEqual( * Record.getRights({ a: Either.right(1), b: Either.left("err"), c: Either.right(2) }), * { a: 1, c: 2 } * ) + * ``` * * @category filtering * @since 2.0.0 @@ -769,11 +815,13 @@ export const getRights = ( * @param f - The predicate function to apply to each element. * * @example + * ```ts * import { Record, Either } from "effect" * * const x = { a: 1, b: 2, c: 3 } * const f = (n: number) => (n % 2 === 0 ? Either.right(n) : Either.left(n)) * assert.deepStrictEqual(Record.partitionMap(x, f), [{ a: 1, c: 3 }, { b: 2}]) + * ``` * * @category filtering * @since 2.0.0 @@ -815,12 +863,14 @@ export const partitionMap: { * @param self - the record to partition. * * @example + * ```ts * import { Record, Either } from "effect" * * assert.deepStrictEqual( * Record.separate({ a: Either.left("e"), b: Either.right(1) }), * [{ a: "e" }, { b: 1 }] * ) + * ``` * * @category filtering * @since 2.0.0 @@ -836,12 +886,14 @@ export const separate: ( * @param predicate - The partitioning function to determine the partitioning of each value of the record. * * @example + * ```ts * import { partition } from "effect/Record" * * assert.deepStrictEqual( * partition({ a: 1, b: 3 }, (n) => n > 2), * [{ a: 1 }, { b: 3 }] * ) + * ``` * * @category filtering * @since 2.0.0 @@ -915,10 +967,12 @@ export const values = (self: ReadonlyRecord): Array u is Redacted = redacted_.isRe * securely hiding its content. * * @example + * ```ts * import { Redacted } from "effect" * * const API_KEY = Redacted.make("1234567890") + * ``` * * @since 3.3.0 * @category constructors @@ -77,11 +79,13 @@ export const make: (value: A) => Redacted = redacted_.make * with caution, as it exposes the sensitive data. * * @example + * ```ts * import { Redacted } from "effect" * * const API_KEY = Redacted.make("1234567890") * * assert.equal(Redacted.value(API_KEY), "1234567890") + * ``` * * @since 3.3.0 * @category getters @@ -94,6 +98,7 @@ export const value: (self: Redacted) => A = redacted_.value * memory longer than necessary. * * @example + * ```ts * import { Redacted } from "effect" * * const API_KEY = Redacted.make("1234567890") @@ -103,6 +108,7 @@ export const value: (self: Redacted) => A = redacted_.value * Redacted.unsafeWipe(API_KEY) * * assert.throws(() => Redacted.value(API_KEY), new Error("Unable to get redacted value")) + * ``` * * @since 3.3.0 * @category unsafe @@ -115,6 +121,7 @@ export const unsafeWipe: (self: Redacted) => boolean = redacted_.unsafeWip * for comparing `Redacted` instances without exposing their contents. * * @example + * ```ts * import { Redacted, Equivalence } from "effect" * * const API_KEY1 = Redacted.make("1234567890") @@ -125,6 +132,7 @@ export const unsafeWipe: (self: Redacted) => boolean = redacted_.unsafeWip * * assert.equal(equivalence(API_KEY1, API_KEY2), false) * assert.equal(equivalence(API_KEY1, API_KEY3), true) + * ``` * * @category equivalence * @since 3.3.0 diff --git a/packages/effect/src/RegExp.ts b/packages/effect/src/RegExp.ts index 374a2d5b492..0b8d273ff2e 100644 --- a/packages/effect/src/RegExp.ts +++ b/packages/effect/src/RegExp.ts @@ -11,10 +11,12 @@ import * as predicate from "./Predicate.js" * @param input - The value to test. * * @example + * ```ts * import { RegExp } from "effect" * * assert.deepStrictEqual(RegExp.isRegExp(/a/), true) * assert.deepStrictEqual(RegExp.isRegExp("a"), false) + * ``` * * @category guards * @since 3.9.0 @@ -25,9 +27,11 @@ export const isRegExp: (input: unknown) => input is RegExp = predicate.isRegExp * Escapes special characters in a regular expression pattern. * * @example + * ```ts * import { RegExp } from "effect" * * assert.deepStrictEqual(RegExp.escape("a*b"), "a\\*b") + * ``` * * @since 2.0.0 */ diff --git a/packages/effect/src/Request.ts b/packages/effect/src/Request.ts index 97f711a5436..2388561e8a6 100644 --- a/packages/effect/src/Request.ts +++ b/packages/effect/src/Request.ts @@ -125,6 +125,7 @@ export const tagged: & { _tag: string }>( * Provides a constructor for a Request Class. * * @example + * ```ts * import { Request } from "effect" * * type Success = string @@ -133,6 +134,7 @@ export const tagged: & { _tag: string }>( * class MyRequest extends Request.Class {} + * ``` * * @since 2.0.0 * @category constructors @@ -146,6 +148,7 @@ export const Class: new>( * Provides a Tagged constructor for a Request Class. * * @example + * ```ts * import { Request } from "effect" * * type Success = string @@ -154,6 +157,7 @@ export const Class: new>( * class MyRequest extends Request.TaggedClass("MyRequest") {} + * ``` * * @since 2.0.0 * @category constructors diff --git a/packages/effect/src/RequestResolver.ts b/packages/effect/src/RequestResolver.ts index f1cc5ff5169..7b36f6aae6f 100644 --- a/packages/effect/src/RequestResolver.ts +++ b/packages/effect/src/RequestResolver.ts @@ -168,6 +168,7 @@ export const around: { * @since 2.0.0 * @category combinators * @example + * ```ts * import { Effect, Request, RequestResolver } from "effect" * * interface GetUserById extends Request.Request { @@ -183,6 +184,7 @@ export const around: { * (requests) => Effect.log(`got ${requests.length} requests`), * (requests, _) => Effect.log(`finised running ${requests.length} requests`) * ) + * ``` */ export const aroundRequests: { ( diff --git a/packages/effect/src/Runtime.ts b/packages/effect/src/Runtime.ts index d6103c25bbd..f1db056bb3d 100644 --- a/packages/effect/src/Runtime.ts +++ b/packages/effect/src/Runtime.ts @@ -271,6 +271,7 @@ export const updateContext: { * @since 2.0.0 * @category context * @example + * ```ts * import { Context, Runtime } from "effect" * * class Name extends Context.Tag("Name")() {} @@ -278,6 +279,7 @@ export const updateContext: { * const runtime: Runtime.Runtime = Runtime.defaultRuntime.pipe( * Runtime.provideService(Name, "John") * ) + * ``` */ export const provideService: { (tag: Context.Tag, service: S): (self: Runtime) => Runtime @@ -297,6 +299,7 @@ export const updateFiberRefs: { * @since 2.0.0 * @category fiber refs * @example + * ```ts * import { Effect, FiberRef, Runtime } from "effect" * * const ref = FiberRef.unsafeMake(0) @@ -307,6 +310,7 @@ export const updateFiberRefs: { * * // returns 1 * const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref)) + * ``` */ export const setFiberRef: { (fiberRef: FiberRef.FiberRef, value: A): (self: Runtime) => Runtime @@ -317,6 +321,7 @@ export const setFiberRef: { * @since 2.0.0 * @category fiber refs * @example + * ```ts * import { Effect, FiberRef, Runtime } from "effect" * * const ref = FiberRef.unsafeMake(0) @@ -328,6 +333,7 @@ export const setFiberRef: { * * // returns 0 * const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref)) + * ``` */ export const deleteFiberRef: { (fiberRef: FiberRef.FiberRef): (self: Runtime) => Runtime diff --git a/packages/effect/src/Schema.ts b/packages/effect/src/Schema.ts index bef17d05ad2..93450261e72 100644 --- a/packages/effect/src/Schema.ts +++ b/packages/effect/src/Schema.ts @@ -100,24 +100,23 @@ export interface SchemaClass extends AnnotableClass(ast: AST.AST): SchemaClass => - class SchemaClass { - [TypeId] = variance - static Type: A - static Encoded: I - static Context: R - static [TypeId] = variance - static ast = ast - static annotations(annotations: Annotations.Schema) { - return make(mergeSchemaAnnotations(this.ast, annotations)) - } - static pipe() { - return pipeArguments(this, arguments) - } - static toString() { - return String(ast) - } +export const make = (ast: AST.AST): SchemaClass => (class SchemaClass { + [TypeId] = variance + static Type: A + static Encoded: I + static Context: R + static [TypeId] = variance + static ast = ast + static annotations(annotations: Annotations.Schema) { + return make(mergeSchemaAnnotations(this.ast, annotations)) + } + static pipe() { + return pipeArguments(this, arguments) } + static toString() { + return String(ast) + } +}) const variance = { /* c8 ignore next */ @@ -601,13 +600,12 @@ const getDefaultLiteralAST = >( literals: Literals, ast: AST.AST = getDefaultLiteralAST(literals) -): Literal => - class LiteralClass extends make(ast) { - static override annotations(annotations: Annotations.Schema): Literal { - return makeLiteralClass(this.literals, mergeSchemaAnnotations(this.ast, annotations)) - } - static literals = [...literals] as Literals +): Literal => (class LiteralClass extends make(ast) { + static override annotations(annotations: Annotations.Schema): Literal { + return makeLiteralClass(this.literals, mergeSchemaAnnotations(this.ast, annotations)) } + static literals = [...literals] as Literals +}) /** * @category constructors @@ -630,6 +628,7 @@ export function Literal>( * Creates a new `Schema` from a literal schema. * * @example + * ```ts * import * as Schema from "effect/Schema" * import { Either } from "effect" * @@ -638,6 +637,7 @@ export function Literal>( * assert.deepStrictEqual(Schema.decodeSync(schema)("a"), "a") * assert.deepStrictEqual(Schema.decodeSync(schema)("b"), "b") * assert.strictEqual(Either.isLeft(Schema.decodeUnknownEither(schema)("c")), true) + * ``` * * @category constructors * @since 3.10.0 @@ -675,15 +675,14 @@ const getDefaultEnumsAST = (enums: A) => const makeEnumsClass = ( enums: A, ast: AST.AST = getDefaultEnumsAST(enums) -): Enums => - class EnumsClass extends make(ast) { - static override annotations(annotations: Annotations.Schema) { - return makeEnumsClass(this.enums, mergeSchemaAnnotations(this.ast, annotations)) - } - - static enums = { ...enums } +): Enums => (class EnumsClass extends make(ast) { + static override annotations(annotations: Annotations.Schema) { + return makeEnumsClass(this.enums, mergeSchemaAnnotations(this.ast, annotations)) } + static enums = { ...enums } +}) + /** * @category constructors * @since 3.10.0 @@ -1106,17 +1105,18 @@ const getDefaultUnionAST = >(members: Me const makeUnionClass = >( members: Members, ast: AST.AST = getDefaultUnionAST(members) -): Union => - class UnionClass - extends make, Schema.Encoded, Schema.Context>(ast) - { - static override annotations(annotations: Annotations.Schema>): Union { - return makeUnionClass(this.members, mergeSchemaAnnotations(this.ast, annotations)) - } - - static members = [...members] +): Union< + Members +> => (class UnionClass + extends make, Schema.Encoded, Schema.Context>(ast) +{ + static override annotations(annotations: Annotations.Schema>): Union { + return makeUnionClass(this.members, mergeSchemaAnnotations(this.ast, annotations)) } + static members = [...members] +}) + /** * @category combinators * @since 3.10.0 @@ -1334,22 +1334,21 @@ const makeTupleTypeClass = - class TupleTypeClass extends make< - TupleType.Type, - TupleType.Encoded, - Schema.Context | Schema.Context - >(ast) { - static override annotations( - annotations: Annotations.Schema> - ): TupleType { - return makeTupleTypeClass(this.elements, this.rest, mergeSchemaAnnotations(this.ast, annotations)) - } +) => (class TupleTypeClass extends make< + TupleType.Type, + TupleType.Encoded, + Schema.Context | Schema.Context +>(ast) { + static override annotations( + annotations: Annotations.Schema> + ): TupleType { + return makeTupleTypeClass(this.elements, this.rest, mergeSchemaAnnotations(this.ast, annotations)) + } - static elements = [...elements] as any as Elements + static elements = [...elements] as any as Elements - static rest = [...rest] as any as Rest - } + static rest = [...rest] as any as Rest +}) /** * @category api interface @@ -1383,15 +1382,17 @@ export interface Array$ extends TupleType<[], [Value]> annotations(annotations: Annotations.Schema>): Array$ } -const makeArrayClass = (value: Value, ast?: AST.AST): Array$ => - class ArrayClass extends makeTupleTypeClass<[], [Value]>([], [value], ast) { - static override annotations(annotations: Annotations.Schema>) { - return makeArrayClass(this.value, mergeSchemaAnnotations(this.ast, annotations)) - } - - static value = value +const makeArrayClass = ( + value: Value, + ast?: AST.AST +): Array$ => (class ArrayClass extends makeTupleTypeClass<[], [Value]>([], [value], ast) { + static override annotations(annotations: Annotations.Schema>) { + return makeArrayClass(this.value, mergeSchemaAnnotations(this.ast, annotations)) } + static value = value +}) + const Array$ = (value: Value): Array$ => makeArrayClass(value) export { @@ -1411,15 +1412,19 @@ export interface NonEmptyArray extends TupleType<[Valu annotations(annotations: Annotations.Schema>): NonEmptyArray } -const makeNonEmptyArrayClass = (value: Value, ast?: AST.AST): NonEmptyArray => - class NonEmptyArrayClass extends makeTupleTypeClass<[Value], [Value]>([value], [value], ast) { - static override annotations(annotations: Annotations.Schema>) { - return makeNonEmptyArrayClass(this.value, mergeSchemaAnnotations(this.ast, annotations)) - } - - static value = value +const makeNonEmptyArrayClass = ( + value: Value, + ast?: AST.AST +): NonEmptyArray< + Value +> => (class NonEmptyArrayClass extends makeTupleTypeClass<[Value], [Value]>([value], [value], ast) { + static override annotations(annotations: Annotations.Schema>) { + return makeNonEmptyArrayClass(this.value, mergeSchemaAnnotations(this.ast, annotations)) } + static value = value +}) + /** * @category constructors * @since 3.10.0 @@ -2722,6 +2727,7 @@ export interface tag extends PropertySignature<":" * @see {@link TaggedStruct} * * @example + * ```ts * import { Schema } from "effect" * * const User = Schema.Struct({ @@ -2731,6 +2737,7 @@ export interface tag extends PropertySignature<":" * }) * * assert.deepStrictEqual(User.make({ name: "John", age: 44 }), { _tag: "User", name: "John", age: 44 }) + * ``` * * @since 3.10.0 */ @@ -2751,6 +2758,7 @@ export type TaggedStruct extends Typ ): Record$ } -const makeRecordClass = (key: K, value: V, ast?: AST.AST): Record$ => - class RecordClass extends makeTypeLiteralClass({}, [{ key, value }], ast) { - static override annotations( - annotations: Annotations.Schema>> - ) { - return makeRecordClass(key, value, mergeSchemaAnnotations(this.ast, annotations)) - } +const makeRecordClass = ( + key: K, + value: V, + ast?: AST.AST +): Record$ => (class RecordClass extends makeTypeLiteralClass({}, [{ key, value }], ast) { + static override annotations( + annotations: Annotations.Schema>> + ) { + return makeRecordClass(key, value, mergeSchemaAnnotations(this.ast, annotations)) + } - static key = key + static key = key - static value = value - } + static value = value +}) /** * @category constructors @@ -2824,6 +2836,7 @@ export const omit = >(...key * producing a new schema that represents a transformation from the `{ readonly [key]: I[K] }` type to `A[K]`. * * @example + * ```ts * import * as Schema from "effect/Schema" * * // --------------------------------------------- @@ -2843,6 +2856,7 @@ export const omit = >(...key * * console.log(Schema.decodeUnknownEither(Schema.Array(pullOutColumn))([{ column1: "1", column2: 100 }, { column1: "2", column2: 300 }])) * // Output: { _id: 'Either', _tag: 'Right', right: [ 1, 2 ] } + * ``` * * @category struct transformations * @since 3.10.0 @@ -2895,16 +2909,17 @@ export interface brand annotations(annotations: Annotations.Schema & Brand>): brand } -const makeBrandClass = (ast: AST.AST): brand => - class BrandClass extends make & Brand, Schema.Encoded, Schema.Context>(ast) { - static override annotations(annotations: Annotations.Schema & Brand>): brand { - return makeBrandClass(mergeSchemaAnnotations(this.ast, annotations)) - } +const makeBrandClass = ( + ast: AST.AST +): brand => (class BrandClass extends make & Brand, Schema.Encoded, Schema.Context>(ast) { + static override annotations(annotations: Annotations.Schema & Brand>): brand { + return makeBrandClass(mergeSchemaAnnotations(this.ast, annotations)) + } - static make = (a: Brand.Unbranded & Brand>, options?: MakeOptions): Schema.Type & Brand => { - return getDisableValidationMakeOption(options) ? a : ParseResult.validateSync(this)(a) - } + static make = (a: Brand.Unbranded & Brand>, options?: MakeOptions): Schema.Type & Brand => { + return getDisableValidationMakeOption(options) ? a : ParseResult.validateSync(this)(a) } +}) /** * Returns a nominal branded schema by applying a brand to a given schema. @@ -2917,10 +2932,12 @@ const makeBrandClass = (ast: AS * @param brand - The brand to apply. * * @example + * ```ts * import * as Schema from "effect/Schema" * * const Int = Schema.Number.pipe(Schema.int(), Schema.brand("Int")) * type Int = Schema.Schema.Type // number & Brand<"Int"> + * ``` * * @category branding * @since 3.10.0 @@ -3208,6 +3225,7 @@ export interface extend extend * - A suspend of a struct with a supported schema * * @example + * ```ts * import * as Schema from "effect/Schema" * * const schema = Schema.Struct({ @@ -3229,6 +3247,7 @@ export interface extend extend * Schema.extend(Schema.Struct({ c: Schema.String })), // <= you can add more fields * Schema.extend(Schema.Record({ key: Schema.String, value: Schema.String })) // <= you can add index signatures * )) + * ``` * * @category combinators * @since 3.10.0 @@ -3334,22 +3353,21 @@ const makeRefineClass = ( self: AST.Refinement ) => option_.Option, ast: AST.AST -): refine => - class RefineClass extends make, Schema.Context>(ast) { - static override annotations(annotations: Annotations.Schema): refine { - return makeRefineClass(this.from, this.filter, mergeSchemaAnnotations(this.ast, annotations)) - } +): refine => (class RefineClass extends make, Schema.Context>(ast) { + static override annotations(annotations: Annotations.Schema): refine { + return makeRefineClass(this.from, this.filter, mergeSchemaAnnotations(this.ast, annotations)) + } - static [RefineSchemaId] = from + static [RefineSchemaId] = from - static from = from + static from = from - static filter = filter + static filter = filter - static make = (a: Schema.Type, options?: MakeOptions): A => { - return getDisableValidationMakeOption(options) ? a : ParseResult.validateSync(this)(a) - } + static make = (a: Schema.Type, options?: MakeOptions): A => { + return getDisableValidationMakeOption(options) ? a : ParseResult.validateSync(this)(a) } +}) /** * @category api interface @@ -3531,22 +3549,25 @@ const makeTransformationClass = => - class TransformationClass - extends make, Schema.Encoded, Schema.Context | Schema.Context | R>(ast) - { - static override annotations(annotations: Annotations.Schema>) { - return makeTransformationClass( - this.from, - this.to, - mergeSchemaAnnotations(this.ast, annotations) - ) - } +): transformOrFail< + From, + To, + R +> => (class TransformationClass + extends make, Schema.Encoded, Schema.Context | Schema.Context | R>(ast) +{ + static override annotations(annotations: Annotations.Schema>) { + return makeTransformationClass( + this.from, + this.to, + mergeSchemaAnnotations(this.ast, annotations) + ) + } - static from = from + static from = from - static to = to - } + static to = to +}) /** * Create a new `Schema` by transforming the input and output of an existing `Schema` @@ -3721,11 +3742,13 @@ export interface transformLiteral extends Annotable * Optionally, you can pass a schema `Schema` to obtain an `A` type instead of `unknown`. * * @example + * ```ts * import * as Schema from "effect/Schema" * * assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson())(`{"a":"1"}`), { a: "1" }) * assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson(Schema.Struct({ a: Schema.NumberFromString })))(`{"a":"1"}`), { a: 1 }) + * ``` * * @category string transformations * @since 3.10.0 @@ -4958,6 +4989,7 @@ export const JsonNumberSchemaId: unique symbol = Symbol.for("effect/SchemaId/Jso * format. * * @example + * ```ts * import * as Schema from "effect/Schema" * * const is = Schema.is(S.JsonNumber) @@ -4966,6 +4998,7 @@ export const JsonNumberSchemaId: unique symbol = Symbol.for("effect/SchemaId/Jso * assert.deepStrictEqual(is(Number.NaN), false) * assert.deepStrictEqual(is(Number.POSITIVE_INFINITY), false) * assert.deepStrictEqual(is(Number.NEGATIVE_INFINITY), false) + * ``` * * @category number constructors * @since 3.10.0 @@ -6601,11 +6634,13 @@ export const OptionFromUndefinedOr = ( * `none` for invalid inputs and `some` for valid non-empty strings. * * @example + * ```ts * 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") + * ``` * * @category Option transformations * @since 3.10.0 @@ -6791,10 +6826,12 @@ export interface EitherFromUnion ext /** * @example + * ```ts * import * as Schema from "effect/Schema" * * // Schema> * Schema.EitherFromUnion({ left: Schema.String, right: Schema.Number }) + * ``` * * @category Either transformations * @since 3.10.0 @@ -7755,6 +7792,7 @@ export interface Class("MyClass")({ @@ -7772,6 +7810,7 @@ export interface Class(identifier: string): ( fields: newFields | HasFields, @@ -7789,6 +7828,7 @@ export interface Class("MyClass")({ @@ -7813,6 +7853,7 @@ export interface Class(identifier: string): < newFields extends Struct.Fields, @@ -7846,6 +7887,7 @@ export interface Class("MyClass")({ @@ -7870,6 +7912,7 @@ export interface Class(identifier: string): < newFields extends Struct.Fields, @@ -7922,6 +7965,7 @@ const getFieldsFromFieldsOr = (fieldsOr: Fields | /** * @example + * ```ts * import { Schema } from "effect" * * class MyClass extends Schema.Class("MyClass")({ @@ -7931,6 +7975,7 @@ const getFieldsFromFieldsOr = (fieldsOr: Fields | * return this.someField + "bar" * } * } + * ``` * * @category classes * @since 3.10.0 @@ -7982,11 +8027,13 @@ export interface TaggedClass("MyClass")("MyClass", { * a: Schema.String * }) {} + * ``` * * @category classes * @since 3.10.0 @@ -8035,6 +8082,7 @@ export interface TaggedErrorClass("MyError")( @@ -8049,6 +8097,7 @@ export interface TaggedErrorClass("MyRequest")("MyRequest", { @@ -9722,6 +9772,7 @@ export interface TaggedRequestClass< * success: Schema.Number, * payload: { id: Schema.String } * }) {} + * ``` * * @category classes * @since 3.10.0 diff --git a/packages/effect/src/Stream.ts b/packages/effect/src/Stream.ts index c18a6cff5fd..f9684caf9ea 100644 --- a/packages/effect/src/Stream.ts +++ b/packages/effect/src/Stream.ts @@ -193,6 +193,7 @@ export const accumulateChunks: (self: Stream) => Stream(self: Stream) => Stream( * second argument with the `bufferSize` and `strategy` fields. * * @example + * ```ts * import { Effect, Stream } from "effect" * * Stream.asyncPush((emit) => @@ -403,6 +410,7 @@ export const asyncEffect: ( * clearInterval(handle) * }) * ), { bufferSize: 16, strategy: "dropping" }) + * ``` * * @since 3.6.0 * @category constructors @@ -458,6 +466,7 @@ export const branchAfter: { * chunks before the slowest downstream stream. * * @example + * ```ts * import { Console, Effect, Fiber, Schedule, Stream } from "effect" * * const numbers = Effect.scoped( @@ -527,6 +536,7 @@ export const branchAfter: { * // Logging to the Console: 19 * // Logging to the Console: 20 * // { _id: 'Chunk', values: [ undefined ] } + * ``` * * @since 2.0.0 * @category utils @@ -684,6 +694,7 @@ export const broadcastedQueuesDynamic: { * of 2 for better performance. * * @example + * ```ts * import { Console, Effect, Schedule, Stream } from "effect" * * const stream = Stream.range(1, 10).pipe( @@ -710,6 +721,7 @@ export const broadcastedQueuesDynamic: { * // after buffering: 5 * // before buffering: 10 * // ... + * ``` * * @since 2.0.0 * @category utils @@ -897,12 +909,14 @@ export const catchSomeCause: { * elements are equal. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.make(1, 1, 1, 2, 2, 3, 4).pipe(Stream.changes) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3, 4 ] } + * ``` * * @since 2.0.0 * @category utils @@ -1036,6 +1050,7 @@ export const combineChunks: { * specified stream. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const s1 = Stream.make(1, 2, 3) @@ -1045,6 +1060,7 @@ export const combineChunks: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3, 4, 5 ] } + * ``` * * @since 2.0.0 * @category utils @@ -1058,6 +1074,7 @@ export const concat: { * Concatenates all of the streams in the chunk to one stream. * * @example + * ```ts * import { Chunk, Effect, Stream } from "effect" * * const s1 = Stream.make(1, 2, 3) @@ -1074,6 +1091,7 @@ export const concat: { * // 5, 6, 7, 8 * // ] * // } + * ``` * * @since 2.0.0 * @category constructors @@ -1088,6 +1106,7 @@ export const concatAll: (streams: Chunk.Chunk>) => Stre * See also `Stream.zip` for the more common point-wise variant. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const s1 = Stream.make(1, 2, 3) @@ -1102,6 +1121,7 @@ export const concatAll: (streams: Chunk.Chunk>) => Stre * // [ 1, "a" ], [ 1, "b" ], [ 2, "a" ], [ 2, "b" ], [ 3, "a" ], [ 3, "b" ] * // ] * // } + * ``` * * @since 2.0.0 * @category utils @@ -1176,6 +1196,7 @@ export const crossWith: { * has paused typing so as to not prematurely recommend results. * * @example + * ```ts * import { Effect, Stream } from "effect" * * let last = Date.now() @@ -1213,6 +1234,7 @@ export const crossWith: { * // Received 8 after 1ms * // > Emitted 8 after 101ms * // { _id: 'Chunk', values: [ 3, 6, 8 ] } + * ``` * * @since 2.0.0 * @category utils @@ -1310,6 +1332,7 @@ export const distributedWithDynamic: { * elements. Useful for sequencing effects using streams: * * @example + * ```ts * import { Effect, Stream } from "effect" * * // We create a stream and immediately drain it. @@ -1317,6 +1340,7 @@ export const distributedWithDynamic: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [] } + * ``` * * @since 2.0.0 * @category utils @@ -1434,12 +1458,14 @@ export const either: (self: Stream) => Stream = internal.empty * Executes the provided finalizer after this stream's finalizers run. * * @example + * ```ts * import { Console, Effect, Stream } from "effect" * * const program = Stream.fromEffect(Console.log("Application Logic.")).pipe( @@ -1464,6 +1491,7 @@ export const empty: Stream = internal.empty * // Finalizing the stream * // Doing some other works after stream's finalization * // { _id: 'Chunk', values: [ undefined, undefined ] } + * ``` * * @since 2.0.0 * @category utils @@ -1537,6 +1565,7 @@ export const execute: (effect: Effect.Effect) => Stream(effect: Effect.Effect) => Stream(evaluate: LazyArg>) => Stream n % 2 === 0)) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] } + * ``` * * @since 2.0.0 * @category filtering @@ -1672,6 +1704,7 @@ export const filterMapWhileEffect: { * when it ends. * * @example + * ```ts * import { Console, Effect, Stream } from "effect" * * const application = Stream.fromEffect(Console.log("Application Logic.")) @@ -1693,6 +1726,7 @@ export const filterMapWhileEffect: { * // Deleting dir: tmp * // Temporary directory was deleted. * // { _id: 'Chunk', values: [ undefined, undefined ] } + * ``` * * @since 2.0.0 * @category constructors @@ -1855,6 +1889,7 @@ export const forever: (self: Stream) => Stream = inte * Creates a stream from an `AsyncIterable`. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const myAsyncIterable = async function*() { @@ -1869,6 +1904,7 @@ export const forever: (self: Stream) => Stream = inte * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -1900,6 +1936,7 @@ export const toChannel: ( * Creates a stream from a `Chunk` of values. * * @example + * ```ts * import { Chunk, Effect, Stream } from "effect" * * // Creating a stream with values from a single Chunk @@ -1907,6 +1944,7 @@ export const toChannel: ( * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -1949,6 +1987,7 @@ export const fromChunkQueue: ( * Creates a stream from an arbitrary number of chunks. * * @example + * ```ts * import { Chunk, Effect, Stream } from "effect" * * // Creating a stream with values from multiple Chunks @@ -1956,6 +1995,7 @@ export const fromChunkQueue: ( * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3, 4, 5, 6 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -1967,12 +2007,14 @@ export const fromChunks: (...chunks: Array>) => Stream = in * with the failure value of this effect. * * @example + * ```ts * import { Effect, Random, Stream } from "effect" * * const stream = Stream.fromEffect(Random.nextInt) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // Example Output: { _id: 'Chunk', values: [ 922694024 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -2027,6 +2069,7 @@ export const fromTPubSub: (pubsub: TPubSub) => Stream = internal.fromTP * Creates a new `Stream` from an iterable collection of values. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const numbers = [1, 2, 3] @@ -2035,6 +2078,7 @@ export const fromTPubSub: (pubsub: TPubSub) => Stream = internal.fromTP * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -2045,6 +2089,7 @@ export const fromIterable: (iterable: Iterable) => Stream = internal.fr * Creates a stream from an effect producing a value of type `Iterable`. * * @example + * ```ts * import { Context, Effect, Stream } from "effect" * * class Database extends Context.Tag("Database")< @@ -2060,6 +2105,7 @@ export const fromIterable: (iterable: Iterable) => Stream = internal.fr * // Stream.runCollect(stream.pipe(Stream.provideService(Database, { getUsers: Effect.succeed(["user1", "user2"]) }))) * // ).then(console.log) * // { _id: 'Chunk', values: [ 'user1', 'user2' ] } + * ``` * * @since 2.0.0 * @category constructors @@ -2162,6 +2208,7 @@ export const fromReadableStreamByob: { * schedule, continuing for as long as the schedule continues. * * @example + * ```ts * import { Effect, Schedule, Stream } from "effect" * * // Emits values every 1 second for a total of 5 emissions @@ -2173,6 +2220,7 @@ export const fromReadableStreamByob: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 0, 1, 2, 3, 4 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -2196,6 +2244,7 @@ export const groupAdjacentBy: { * More powerful version of `Stream.groupByKey`. * * @example + * ```ts * import { Chunk, Effect, GroupBy, Stream } from "effect" * * const groupByKeyResult = Stream.fromIterable([ @@ -2223,6 +2272,7 @@ export const groupAdjacentBy: { * // _id: 'Chunk', * // values: [ [ 'M', 1 ], [ 'J', 3 ], [ 'R', 2 ], [ 'P', 2 ] ] * // } + * ``` * * @since 2.0.0 * @category grouping @@ -2296,6 +2346,7 @@ export const groupByKey: { * Partitions the stream with specified `chunkSize`. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.range(0, 8).pipe(Stream.grouped(3)) @@ -2310,6 +2361,7 @@ export const groupByKey: { * // [length]: 3 * // ] * // } + * ``` * * @since 2.0.0 * @category grouping @@ -2324,6 +2376,7 @@ export const grouped: { * `duration` has passed, whichever is satisfied first. * * @example + * ```ts * import { Chunk, Effect, Schedule, Stream } from "effect" * * const stream = Stream.range(0, 9).pipe( @@ -2359,6 +2412,7 @@ export const grouped: { * // ] * // } * // ] + * ``` * * @since 2.0.0 * @category grouping @@ -2432,6 +2486,7 @@ export const identity: () => Stream = internal * pulled. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const s1 = Stream.make(1, 2, 3) @@ -2441,6 +2496,7 @@ export const identity: () => Stream = internal * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 4, 2, 5, 3, 6 ] } + * ``` * @since 2.0.0 * @category utils */ @@ -2459,6 +2515,7 @@ export const interleave: { * ignored. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const s1 = Stream.make(1, 3, 5, 7, 9) @@ -2476,6 +2533,7 @@ export const interleave: { * // 8, 5, 10, 7, 9 * // ] * // } + * ``` * * @since 2.0.0 * @category utils @@ -2496,6 +2554,7 @@ export const interleaveWith: { * Intersperse stream with provided `element`. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5).pipe(Stream.intersperse(0)) @@ -2508,6 +2567,7 @@ export const interleaveWith: { * // 0, 4, 0, 5 * // ] * // } + * ``` * * @since 2.0.0 * @category utils @@ -2521,6 +2581,7 @@ export const intersperse: { * Intersperse the specified element, also adding a prefix and a suffix. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5).pipe( @@ -2540,6 +2601,7 @@ export const intersperse: { * // ']' * // ] * // } + * ``` * * @since 2.0.0 * @category utils @@ -2603,6 +2665,7 @@ export const interruptWhenDeferred: { * f(f(f(a))), ... * * @example + * ```ts * import { Effect, Stream } from "effect" * * // An infinite Stream of numbers starting from 1 and incrementing @@ -2610,6 +2673,7 @@ export const interruptWhenDeferred: { * * // Effect.runPromise(Stream.runCollect(stream.pipe(Stream.take(10)))).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -2620,12 +2684,14 @@ export const iterate: (value: A, next: (value: A) => A) => Stream = intern * Creates a stream from an sequence of values. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.make(1, 2, 3) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -2636,12 +2702,14 @@ export const make: >(...as: As) => Stream = in * Transforms the elements of this stream using the supplied function. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.make(1, 2, 3).pipe(Stream.map((n) => n + 1)) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 2, 3, 4 ] } + * ``` * * @since 2.0.0 * @category mapping @@ -2655,6 +2723,7 @@ export const map: { * Statefully maps over the elements of this stream to produce new elements. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const runningTotal = (stream: Stream.Stream): Stream.Stream => @@ -2665,6 +2734,7 @@ export const map: { * // console.log * // ) * // { _id: "Chunk", values: [ 0, 1, 3, 6, 10, 15, 21 ] } + * ``` * * @since 2.0.0 * @category mapping @@ -2742,6 +2812,7 @@ export const mapChunksEffect: { * output of this stream. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const numbers = Stream.make("1-2-3", "4-5", "6").pipe( @@ -2751,6 +2822,7 @@ export const mapChunksEffect: { * * // Effect.runPromise(Stream.runCollect(numbers)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3, 4, 5, 6 ] } + * ``` * * @since 2.0.0 * @category mapping @@ -2810,6 +2882,7 @@ export const mapConcatEffect: { * Maps over elements of the stream with the specified effectful function. * * @example + * ```ts * import { Effect, Random, Stream } from "effect" * * const stream = Stream.make(10, 20, 30).pipe( @@ -2818,6 +2891,7 @@ export const mapConcatEffect: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // Example Output: { _id: 'Chunk', values: [ 7, 19, 8 ] } + * ``` * * @since 2.0.0 * @category mapping @@ -2876,6 +2950,7 @@ export const mapErrorCause: { * no termination strategy is specified. * * @example + * ```ts * import { Effect, Schedule, Stream } from "effect" * * const s1 = Stream.make(1, 2, 3).pipe( @@ -2889,6 +2964,7 @@ export const mapErrorCause: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 4, 2, 3, 5, 6 ] } + * ``` * * @since 2.0.0 * @category utils @@ -2935,12 +3011,14 @@ export const mergeAll: { * @since 3.8.5 * * @example + * ```ts * import { Stream } from "effect" * // Stream.Stream<{ _tag: "a"; value: number; } | { _tag: "b"; value: string; }> * const res = Stream.mergeWithTag({ * a: Stream.make(0), * b: Stream.make("") * }, { concurrency: "unbounded" }) + * ``` */ export const mergeWithTag: { }>( @@ -2972,6 +3050,7 @@ export const mergeWithTag: { * no termination strategy is specified. * * @example + * ```ts * import { Effect, Schedule, Stream } from "effect" * * const s1 = Stream.make("1", "2", "3").pipe( @@ -2988,6 +3067,7 @@ export const mergeWithTag: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 4, 2, 3, 5, 6 ] } + * ``` * * @since 2.0.0 * @category utils @@ -3071,6 +3151,7 @@ export const never: Stream = internal.never * Adds an effect to be executed at the end of the stream. * * @example + * ```ts * import { Console, Effect, Stream } from "effect" * * const stream = Stream.make(1, 2, 3).pipe( @@ -3085,6 +3166,7 @@ export const never: Stream = internal.never * // after mapping: 6 * // Stream ended * // { _id: 'Chunk', values: [ 2, 4, 6 ] } + * ``` * * @since 3.6.0 * @category sequencing @@ -3134,6 +3216,7 @@ export const onDone: { * Adds an effect to be executed at the start of the stream. * * @example + * ```ts * import { Console, Effect, Stream } from "effect" * * const stream = Stream.make(1, 2, 3).pipe( @@ -3148,6 +3231,7 @@ export const onDone: { * // after mapping: 4 * // after mapping: 6 * // { _id: 'Chunk', values: [ 2, 4, 6 ] } + * ``` * * @since 3.6.0 * @category sequencing @@ -3277,6 +3361,7 @@ export const orElseSucceed: { * APIs, hence the name. * * @example + * ```ts * import { Effect, Option, Stream } from "effect" * * const stream = Stream.paginate(0, (n) => [ @@ -3286,6 +3371,7 @@ export const orElseSucceed: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 0, 1, 2, 3 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -3338,6 +3424,7 @@ export const paginateEffect: ( * further than the slower one. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const partition = Stream.range(1, 10).pipe( @@ -3355,6 +3442,7 @@ export const paginateEffect: ( * // Effect.runPromise(program) * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] } * // { _id: 'Chunk', values: [ 1, 3, 5, 7, 9 ] } + * ``` * * @since 2.0.0 * @category utils @@ -3389,6 +3477,7 @@ export const partition: { * up to buffer elements further than the slower one. * * @example + * ```ts * import { Effect, Either, Stream } from "effect" * * const partition = Stream.range(1, 9).pipe( @@ -3409,6 +3498,7 @@ export const partition: { * // Effect.runPromise(program) * // { _id: 'Chunk', values: [ 2, 4, 6, 8 ] } * // { _id: 'Chunk', values: [ 1, 3, 5, 7, 9 ] } + * ``` * * @since 2.0.0 * @category utils @@ -3619,6 +3709,7 @@ export const provideSomeLayer: { * Any upstream failures will cause the returned stream to fail. * * @example + * ```ts * import { Stream, Schedule, Console, Effect } from "effect" * * const stream = Stream.fromSchedule(Schedule.spaced('2 millis')).pipe( @@ -3635,6 +3726,7 @@ export const provideSomeLayer: { * // 3 * // 4 * // 5 + * ``` * @since 3.7.0 * @category racing */ @@ -3655,6 +3747,7 @@ export const race: { * Any upstream failures will cause the returned stream to fail. * * @example + * ```ts * import { Stream, Schedule, Console, Effect } from "effect" * * const stream = Stream.raceAll( @@ -3671,6 +3764,7 @@ export const race: { * // 3 * // 4 * // 5 + * ``` * @since 3.5.0 * @category racing */ @@ -3686,6 +3780,7 @@ export const raceAll: >>( * Constructs a stream from a range of integers, including both endpoints. * * @example + * ```ts * import { Effect, Stream } from "effect" * * // A Stream with a range of numbers from 1 to 5 @@ -3693,6 +3788,7 @@ export const raceAll: >>( * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3, 4, 5 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -3742,12 +3838,14 @@ export const refineOrDieWith: { * execute normally, and then repeat again according to the provided schedule. * * @example + * ```ts * import { Effect, Schedule, Stream } from "effect" * * const stream = Stream.repeat(Stream.succeed(1), Schedule.forever) * * // Effect.runPromise(Stream.runCollect(stream.pipe(Stream.take(5)))).then(console.log) * // { _id: 'Chunk', values: [ 1, 1, 1, 1, 1 ] } + * ``` * * @since 2.0.0 * @category utils @@ -3762,12 +3860,14 @@ export const repeat: { * forever. * * @example + * ```ts * import { Effect, Random, Stream } from "effect" * * const stream = Stream.repeatEffect(Random.nextInt) * * // Effect.runPromise(Stream.runCollect(stream.pipe(Stream.take(5)))).then(console.log) * // Example Output: { _id: 'Chunk', values: [ 3891571149, 4239494205, 2352981603, 2339111046, 1488052210 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -3800,6 +3900,7 @@ export const repeatEffectChunkOption: ( * with `None`. * * @example + * ```ts * // In this example, we're draining an Iterator to create a stream from it * import { Stream, Effect, Option } from "effect" * @@ -3814,6 +3915,7 @@ export const repeatEffectChunkOption: ( * }) * ) * ) + * ``` * * @since 2.0.0 * @category constructors @@ -3897,12 +3999,14 @@ export const repeatElementsWith: { * Repeats the provided value infinitely. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.repeatValue(0) * * // Effect.runPromise(Stream.runCollect(stream.pipe(Stream.take(5)))).then(console.log) * // { _id: 'Chunk', values: [ 0, 0, 0, 0, 0 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -4356,12 +4460,14 @@ export const runSum: (self: Stream) => Effect.Effect a + b)) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 0, 1, 3, 6, 10, 15, 21 ] } + * ``` * * @since 2.0.0 * @category utils @@ -4460,6 +4566,7 @@ export const scheduleWith: { * Creates a single-valued stream from a scoped resource. * * @example + * ```ts * import { Console, Effect, Stream } from "effect" * * // Creating a single-valued stream from a scoped resource @@ -4476,6 +4583,7 @@ export const scheduleWith: { * // use * // release * // { _id: 'Chunk', values: [ undefined ] } + * ``` * * @since 2.0.0 * @category constructors @@ -4598,6 +4706,7 @@ export const splitLines: (self: Stream) => Stream(self: Stream) => Stream(stream: LazyArg>) => Stream n + 1), 5) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 0, 1, 2, 3, 4 ] } + * ``` * * @since 2.0.0 * @category utils @@ -4650,12 +4762,14 @@ export const take: { * Takes the last specified number of elements from this stream. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.takeRight(Stream.make(1, 2, 3, 4, 5, 6), 3) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 4, 5, 6 ] } + * ``` * * @since 2.0.0 * @category utils @@ -4670,12 +4784,14 @@ export const takeRight: { * `true`. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.takeUntil(Stream.iterate(0, (n) => n + 1), (n) => n === 4) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 0, 1, 2, 3, 4 ] } + * ``` * * @since 2.0.0 * @category utils @@ -4707,12 +4823,14 @@ export const takeUntilEffect: { * evaluates to `true`. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.takeWhile(Stream.iterate(0, (n) => n + 1), (n) => n < 5) * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ 0, 1, 2, 3, 4 ] } + * ``` * * @since 2.0.0 * @category utils @@ -4728,6 +4846,7 @@ export const takeWhile: { * Adds an effect to consumption of every element of the stream. * * @example + * ```ts * import { Console, Effect, Stream } from "effect" * * const stream = Stream.make(1, 2, 3).pipe( @@ -4744,6 +4863,7 @@ export const takeWhile: { * // before mapping: 3 * // after mapping: 6 * // { _id: 'Chunk', values: [ 2, 4, 6 ] } + * ``` * * @since 2.0.0 * @category sequencing @@ -4834,6 +4954,7 @@ export const tapSink: { * Defaults to the "shape" strategy. * * @example + * ```ts * import { Chunk, Effect, Schedule, Stream } from "effect" * * let last = Date.now() @@ -4869,6 +4990,7 @@ export const tapSink: { * // Received 5 after 52ms * // > Emitted 5 after 49ms * // { _id: 'Chunk', values: [ 0, 1, 2, 3, 4, 5 ] } + * ``` * * @since 2.0.0 * @category utils @@ -4937,6 +5059,7 @@ export const throttleEffect: { * A stream that emits void values spaced by the specified duration. * * @example + * ```ts * import { Effect, Stream } from "effect" * * let last = Date.now() @@ -4956,6 +5079,7 @@ export const throttleEffect: { * // tick after 1002ms * // tick after 1002ms * // { _id: 'Chunk', values: [ undefined, undefined, undefined, undefined, undefined ] } + * ``` * * @since 2.0.0 * @category constructors @@ -5055,6 +5179,7 @@ export const toPubSub: { * the stream's output. * * @example + * ```ts * import { Effect, Stream } from "effect" * * // Simulate a chunked stream @@ -5079,6 +5204,7 @@ export const toPubSub: { * // "_id": "Option", * // "_tag": "None" * // } + * ``` * * @since 2.0.0 * @category destructors @@ -5208,12 +5334,14 @@ export const transduce: { * Creates a stream by peeling off the "layers" of a value of type `S`. * * @example + * ```ts * import { Effect, Option, Stream } from "effect" * * const stream = Stream.unfold(1, (n) => Option.some([n, n + 1])) * * // Effect.runPromise(Stream.runCollect(stream.pipe(Stream.take(5)))).then(console.log) * // { _id: 'Chunk', values: [ 1, 2, 3, 4, 5 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -5248,6 +5376,7 @@ export const unfoldChunkEffect: ( * `S`. * * @example + * ```ts * import { Effect, Option, Random, Stream } from "effect" * * const stream = Stream.unfoldEffect(1, (n) => @@ -5257,6 +5386,7 @@ export const unfoldChunkEffect: ( * * // Effect.runPromise(Stream.runCollect(stream.pipe(Stream.take(5)))).then(console.log) * // { _id: 'Chunk', values: [ 1, -1, -1, -1, -1 ] } + * ``` * * @since 2.0.0 * @category constructors @@ -5272,6 +5402,7 @@ export { * A stream that contains a single `void` value. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.void @@ -5279,6 +5410,7 @@ export { * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ undefined ] } * + * ``` * @since 2.0.0 * @category constructors */ @@ -5400,6 +5532,7 @@ export const withSpan: { * The new stream will end when one of the sides ends. * * @example + * ```ts * import { Effect, Stream } from "effect" * * // We create two streams and zip them together. @@ -5410,6 +5543,7 @@ export const withSpan: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ] ] } + * ``` * * @since 2.0.0 * @category zipping @@ -5446,6 +5580,7 @@ export const zipFlatten: { * have different lengths and one of the streams has ended before the other. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.zipAll(Stream.make(1, 2, 3, 4, 5, 6), { @@ -5456,6 +5591,7 @@ export const zipFlatten: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: "Chunk", values: [ [ 1, "a" ], [ 2, "b" ], [ 3, "c" ], [ 4, "x" ], [ 5, "x" ], [ 6, "x" ] ] } + * ``` * * @since 2.0.0 * @category zipping @@ -5643,6 +5779,7 @@ export const zipAllSortedByKeyWith: { * lengths and one of the streams has ended before the other. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.zipAllWith(Stream.make(1, 2, 3, 4, 5, 6), { @@ -5654,6 +5791,7 @@ export const zipAllSortedByKeyWith: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: "Chunk", values: [ [ 0, "a" ], [ 1, "b" ], [ 2, "c" ], [ 4, "x" ], [ 5, "x" ], [ 6, "x" ] ] } + * ``` * * @since 2.0.0 * @category zipping @@ -5688,6 +5826,7 @@ export const zipAllWith: { * used for zipping. * * @example + * ```ts * import { Effect, Schedule, Stream } from "effect" * * const s1 = Stream.make(1, 2, 3).pipe( @@ -5702,6 +5841,7 @@ export const zipAllWith: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: "Chunk", values: [ [ 1, "a" ], [ 1, "b" ], [ 2, "b" ], [ 2, "c" ], [ 2, "d" ], [ 3, "d" ] ] } + * ``` * * @since 2.0.0 * @category zipping @@ -5720,6 +5860,7 @@ export const zipLatest: { * used for zipping. * * @example + * ```ts * import { Stream, Schedule, Console, Effect } from "effect" * * const stream = Stream.zipLatestAll( @@ -5737,6 +5878,7 @@ export const zipLatest: { * // [ 3, 1, 0 ] * // [ 3, 1, 1 ] * // ..... + * ``` * * @since 3.3.0 * @category zipping @@ -5809,6 +5951,7 @@ export const zipRight: { * The new stream will end when one of the sides ends. * * @example + * ```ts * import { Effect, Stream } from "effect" * * // We create two streams and zip them with custom logic. @@ -5820,6 +5963,7 @@ export const zipRight: { * * // Effect.runPromise(Stream.runCollect(stream)).then(console.log) * // { _id: 'Chunk', values: [ [ 0, 'a' ], [ 1, 'b' ], [ 2, 'c' ] ] } + * ``` * * @since 2.0.0 * @category zipping @@ -5867,6 +6011,7 @@ export const zipWithChunks: { * Zips each element with the next element if present. * * @example + * ```ts * import { Chunk, Effect, Stream } from "effect" * * const stream = Stream.zipWithNext(Stream.make(1, 2, 3, 4)) @@ -5878,6 +6023,7 @@ export const zipWithChunks: { * // [ 3, { _id: 'Option', _tag: 'Some', value: 4 } ], * // [ 4, { _id: 'Option', _tag: 'None' } ] * // ] + * ``` * * @since 2.0.0 * @category zipping @@ -5889,6 +6035,7 @@ export const zipWithNext: (self: Stream) => Stream<[A, Option. * `None`. * * @example + * ```ts * import { Chunk, Effect, Stream } from "effect" * * const stream = Stream.zipWithPrevious(Stream.make(1, 2, 3, 4)) @@ -5900,6 +6047,7 @@ export const zipWithNext: (self: Stream) => Stream<[A, Option. * // [ { _id: 'Option', _tag: 'Some', value: 2 }, 3 ], * // [ { _id: 'Option', _tag: 'Some', value: 3 }, 4 ] * // ] + * ``` * * @since 2.0.0 * @category zipping @@ -5911,6 +6059,7 @@ export const zipWithPrevious: (self: Stream) => Stream<[Option * Zips each element with both the previous and next element. * * @example + * ```ts * import { Chunk, Effect, Stream } from "effect" * * const stream = Stream.zipWithPreviousAndNext(Stream.make(1, 2, 3, 4)) @@ -5938,6 +6087,7 @@ export const zipWithPrevious: (self: Stream) => Stream<[Option * // { _id: 'Option', _tag: 'None' } * // ] * // ] + * ``` * * @since 2.0.0 * @category zipping @@ -5950,6 +6100,7 @@ export const zipWithPreviousAndNext: ( * Zips this stream together with the index of elements. * * @example + * ```ts * import { Effect, Stream } from "effect" * * const stream = Stream.make("Mary", "James", "Robert", "Patricia") @@ -5961,6 +6112,7 @@ export const zipWithPreviousAndNext: ( * // _id: 'Chunk', * // values: [ [ 'Mary', 0 ], [ 'James', 1 ], [ 'Robert', 2 ], [ 'Patricia', 3 ] ] * // } + * ``` * * @since 2.0.0 * @category zipping @@ -5987,6 +6139,7 @@ export const zipWithIndex: (self: Stream) => Stream<[A, number * @see {@link let_ let} * * @example + * ```ts * import { Chunk, Effect, pipe, Stream } from "effect" * * const result = pipe( @@ -5996,6 +6149,7 @@ export const zipWithIndex: (self: Stream) => Stream<[A, number * Stream.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(Effect.runSync(Stream.runCollect(result)), Chunk.of({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -6018,6 +6172,7 @@ export const Do: Stream<{}> = internal.Do * @see {@link let_ let} * * @example + * ```ts * import { Chunk, Effect, pipe, Stream } from "effect" * * const result = pipe( @@ -6027,6 +6182,7 @@ export const Do: Stream<{}> = internal.Do * Stream.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(Effect.runSync(Stream.runCollect(result)), Chunk.of({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -6090,6 +6246,7 @@ export const bindEffect: { * @see {@link let_ let} * * @example + * ```ts * import { Chunk, Effect, pipe, Stream } from "effect" * * const result = pipe( @@ -6099,6 +6256,7 @@ export const bindEffect: { * Stream.let("sum", ({ x, y }) => x + y) * ) * assert.deepStrictEqual(Effect.runSync(Stream.runCollect(result)), Chunk.of({ x: 2, y: 3, sum: 5 })) + * ``` * * @category do notation * @since 2.0.0 @@ -6137,6 +6295,7 @@ export { * @see {@link bindEffect} * * @example + * ```ts * import { Chunk, Effect, pipe, Stream } from "effect" * * const result = pipe( @@ -6147,6 +6306,7 @@ export { * ) * assert.deepStrictEqual(Effect.runSync(Stream.runCollect(result)), Chunk.of({ x: 2, y: 3, sum: 5 })) * + * ``` * @category do notation * @since 2.0.0 */ diff --git a/packages/effect/src/String.ts b/packages/effect/src/String.ts index 440099c0728..ce8e0e424c9 100644 --- a/packages/effect/src/String.ts +++ b/packages/effect/src/String.ts @@ -23,10 +23,12 @@ import * as predicate from "./Predicate.js" * @param input - The value to test. * * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.isString("a"), true) * assert.deepStrictEqual(String.isString(1), false) + * ``` * * @category guards * @since 2.0.0 @@ -71,9 +73,11 @@ export const concat: { /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe('a', String.toUpperCase), 'A') + * ``` * * @since 2.0.0 */ @@ -81,9 +85,11 @@ export const toUpperCase = (self: S): Uppercase => self.toU /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe('A', String.toLowerCase), 'a') + * ``` * * @since 2.0.0 */ @@ -91,9 +97,11 @@ export const toLowerCase = (self: T): Lowercase => self.toL /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe('abc', String.capitalize), 'Abc') + * ``` * * @since 2.0.0 */ @@ -105,9 +113,11 @@ export const capitalize = (self: T): Capitalize => { /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe('ABC', String.uncapitalize), 'aBC') + * ``` * * @since 2.0.0 */ @@ -119,9 +129,11 @@ export const uncapitalize = (self: T): Uncapitalize => { /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe('abc', String.replace('b', 'd')), 'adc') + * ``` * * @since 2.0.0 */ @@ -135,9 +147,11 @@ export type Trim = TrimEnd> /** * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.trim(' a '), 'a') + * ``` * * @since 2.0.0 */ @@ -150,9 +164,11 @@ export type TrimStart = A extends `${" " | "\n" | "\t" | "\r"} /** * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.trimStart(' a '), 'a ') + * ``` * * @since 2.0.0 */ @@ -165,9 +181,11 @@ export type TrimEnd = A extends `${infer B}${" " | "\n" | "\t" /** * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.trimEnd(' a '), ' a') + * ``` * * @since 2.0.0 */ @@ -175,9 +193,11 @@ export const trimEnd = (self: A): TrimEnd => self.trimEnd() /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe('abcd', String.slice(1, 3)), 'bc') + * ``` * * @since 2.0.0 */ @@ -187,10 +207,12 @@ export const slice = (start?: number, end?: number) => (self: string): string => * Test whether a `string` is empty. * * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.isEmpty(''), true) * assert.deepStrictEqual(String.isEmpty('a'), false) + * ``` * * @since 2.0.0 */ @@ -207,9 +229,11 @@ export const isNonEmpty = (self: string): boolean => self.length > 0 * Calculate the number of characters in a `string`. * * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.length('abc'), 3) + * ``` * * @since 2.0.0 */ @@ -217,10 +241,12 @@ export const length = (self: string): number => self.length /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe('abc', String.split('')), ['a', 'b', 'c']) * assert.deepStrictEqual(pipe('', String.split('')), ['']) + * ``` * * @since 2.0.0 */ @@ -255,10 +281,12 @@ export const endsWith = (searchString: string, position?: number) => (self: stri /** * @example + * ```ts * import { pipe, String, Option } from "effect" * * assert.deepStrictEqual(pipe("abc", String.charCodeAt(1)), Option.some(98)) * assert.deepStrictEqual(pipe("abc", String.charCodeAt(4)), Option.none()) + * ``` * * @since 2.0.0 */ @@ -273,10 +301,12 @@ export const charCodeAt: { /** * @example + * ```ts * import { pipe, String, Option } from "effect" * * assert.deepStrictEqual(pipe("abcd", String.substring(1)), "bcd") * assert.deepStrictEqual(pipe("abcd", String.substring(1, 3)), "bc") + * ``` * * @since 2.0.0 */ @@ -284,10 +314,12 @@ export const substring = (start: number, end?: number) => (self: string): string /** * @example + * ```ts * import { pipe, String, Option } from "effect" * * assert.deepStrictEqual(pipe("abc", String.at(1)), Option.some("b")) * assert.deepStrictEqual(pipe("abc", String.at(4)), Option.none()) + * ``` * * @since 2.0.0 */ @@ -298,10 +330,12 @@ export const at: { /** * @example + * ```ts * import { pipe, String, Option } from "effect" * * assert.deepStrictEqual(pipe("abc", String.charAt(1)), Option.some("b")) * assert.deepStrictEqual(pipe("abc", String.charAt(4)), Option.none()) + * ``` * * @since 2.0.0 */ @@ -315,9 +349,11 @@ export const charAt: { /** * @example + * ```ts * import { pipe, String, Option } from "effect" * * assert.deepStrictEqual(pipe("abc", String.codePointAt(1)), Option.some(98)) + * ``` * * @since 2.0.0 */ @@ -328,9 +364,11 @@ export const codePointAt: { /** * @example + * ```ts * import { pipe, String, Option } from "effect" * * assert.deepStrictEqual(pipe("abbbc", String.indexOf("b")), Option.some(1)) + * ``` * * @since 2.0.0 */ @@ -339,10 +377,12 @@ export const indexOf = (searchString: string) => (self: string): Option.Option (self: string): Option.Opti /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe("a", String.localeCompare("b")), -1) * assert.deepStrictEqual(pipe("b", String.localeCompare("a")), 1) * assert.deepStrictEqual(pipe("a", String.localeCompare("a")), 0) + * ``` * * @since 2.0.0 */ @@ -380,6 +422,7 @@ export const matchAll = (regexp: RegExp) => (self: string): IterableIterator (self: string): IterableIterator (self: stri /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe("a", String.padEnd(5)), "a ") * assert.deepStrictEqual(pipe("a", String.padEnd(5, "_")), "a____") + * ``` * * @since 2.0.0 */ @@ -407,10 +453,12 @@ export const padEnd = (maxLength: number, fillString?: string) => (self: string) /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe("a", String.padStart(5)), " a") * assert.deepStrictEqual(pipe("a", String.padStart(5, "_")), "____a") + * ``` * * @since 2.0.0 */ @@ -419,9 +467,11 @@ export const padStart = (maxLength: number, fillString?: string) => (self: strin /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe("a", String.repeat(5)), "aaaaa") + * ``` * * @since 2.0.0 */ @@ -429,10 +479,12 @@ export const repeat = (count: number) => (self: string): string => self.repeat(c /** * @example + * ```ts * import { pipe, String } from "effect" * * assert.deepStrictEqual(pipe("ababb", String.replaceAll("b", "c")), "acacc") * assert.deepStrictEqual(pipe("ababb", String.replaceAll(/ba/g, "cc")), "accbb") + * ``` * * @since 2.0.0 */ @@ -441,11 +493,13 @@ export const replaceAll = (searchValue: string | RegExp, replaceValue: string) = /** * @example + * ```ts * import { pipe, String, Option } from "effect" * * assert.deepStrictEqual(pipe("ababb", String.search("b")), Option.some(1)) * assert.deepStrictEqual(pipe("ababb", String.search(/abb/)), Option.some(2)) * assert.deepStrictEqual(pipe("ababb", String.search("d")), Option.none()) + * ``` * * @since 2.0.0 */ @@ -460,10 +514,12 @@ export const search: { /** * @example + * ```ts * import { pipe, String } from "effect" * * const str = "\u0130" * assert.deepStrictEqual(pipe(str, String.toLocaleLowerCase("tr")), "i") + * ``` * * @since 2.0.0 */ @@ -472,10 +528,12 @@ export const toLocaleLowerCase = (locale?: string | Array) => (self: str /** * @example + * ```ts * import { pipe, String } from "effect" * * const str = "i\u0307" * assert.deepStrictEqual(pipe(str, String.toLocaleUpperCase("lt-LT")), "I") + * ``` * * @since 2.0.0 */ @@ -493,9 +551,11 @@ export const toLocaleUpperCase = (locale?: string | Array) => (self: str * If `n` is a float, it will be rounded down to the nearest integer. * * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.takeLeft("Hello World", 5), "Hello") + * ``` * * @since 2.0.0 */ @@ -515,9 +575,11 @@ export const takeLeft: { * If `n` is a float, it will be rounded down to the nearest integer. * * @example + * ```ts * import { String } from "effect" * * assert.deepStrictEqual(String.takeRight("Hello World", 5), "World") + * ``` * * @since 2.0.0 */ diff --git a/packages/effect/src/Struct.ts b/packages/effect/src/Struct.ts index fdf8da818c7..7d3e3b92d22 100644 --- a/packages/effect/src/Struct.ts +++ b/packages/effect/src/Struct.ts @@ -14,10 +14,12 @@ import type { MatchRecord, Simplify } from "./Types.js" * Create a new object by picking properties of an existing object. * * @example + * ```ts * import { pipe, Struct } from "effect" * * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, Struct.pick("a", "b")), { a: "a", b: 1 }) * assert.deepStrictEqual(Struct.pick({ a: "a", b: 1, c: true }, "a", "b"), { a: "a", b: 1 }) + * ``` * * @since 2.0.0 */ @@ -48,10 +50,12 @@ export const pick: { * Create a new object by omitting properties of an existing object. * * @example + * ```ts * import { pipe, Struct } from "effect" * * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, Struct.omit("c")), { a: "a", b: 1 }) * assert.deepStrictEqual(Struct.omit({ a: "a", b: 1, c: true }, "c"), { a: "a", b: 1 }) + * ``` * * @since 2.0.0 */ @@ -81,6 +85,7 @@ export const omit: { * Alias of {@link Equivalence.struct}. * * @example + * ```ts * import { Struct, String, Number } from "effect" * * const PersonEquivalence = Struct.getEquivalence({ @@ -96,6 +101,7 @@ export const omit: { * PersonEquivalence({ name: "John", age: 25 }, { name: "John", age: 40 }), * false * ) + * ``` * * @category combinators * @since 2.0.0 @@ -132,6 +138,7 @@ type PartialTransform = { * If no transformation function is provided for a key, it will return the origional value for that key. * * @example + * ```ts * import { pipe, Struct } from "effect" * * assert.deepStrictEqual( @@ -144,6 +151,7 @@ type PartialTransform = { * ), * { a: 1, b: 2, c: 3 } * ) + * ``` * * @since 2.0.0 */ @@ -168,11 +176,13 @@ export const evolve: { * Retrieves the value associated with the specified key from a struct. * * @example + * ```ts * import { pipe, Struct } from "effect" * * const value = pipe({ a: 1, b: 2 }, Struct.get("a")) * * assert.deepStrictEqual(value, 1) + * ``` * * @since 2.0.0 */ @@ -184,6 +194,7 @@ export const get = * Retrieves the object keys that are strings in a typed manner * * @example + * ```ts * import { Struct } from "effect" * * const symbol: unique symbol = Symbol() @@ -197,6 +208,7 @@ export const get = * const keys: Array<"a" | "b"> = Struct.keys(value) * * assert.deepStrictEqual(keys, ["a", "b"]) + * ``` * * @since 3.6.0 */ diff --git a/packages/effect/src/Symbol.ts b/packages/effect/src/Symbol.ts index 1f6a6db7512..5b58b2162b7 100644 --- a/packages/effect/src/Symbol.ts +++ b/packages/effect/src/Symbol.ts @@ -11,10 +11,12 @@ import * as predicate from "./Predicate.js" * @param input - The value to test. * * @example + * ```ts * import { Predicate } from "effect" * * assert.deepStrictEqual(Predicate.isSymbol(Symbol.for("a")), true) * assert.deepStrictEqual(Predicate.isSymbol("a"), false) + * ``` * * @category guards * @since 2.0.0 diff --git a/packages/effect/src/Trie.ts b/packages/effect/src/Trie.ts index a5bd4fef96c..0033d02246c 100644 --- a/packages/effect/src/Trie.ts +++ b/packages/effect/src/Trie.ts @@ -44,12 +44,14 @@ export interface Trie extends Iterable<[string, Value]>, Equal, Pi * Creates an empty `Trie`. * * @example + * ```ts * import { Trie, Equal } from "effect" * * const trie = Trie.empty() * * assert.equal(Trie.size(trie), 0) * assert.deepStrictEqual(Array.from(trie), []) + * ``` * * @since 2.0.0 * @category constructors @@ -60,6 +62,7 @@ export const empty: () => Trie = TR.empty * Creates a new `Trie` from an iterable collection of key/value pairs (e.g. `Array<[string, V]>`). * * @example + * ```ts * import { Trie, Equal } from "effect" * * const iterable: Array = [["call", 0], ["me", 1], ["mind", 2], ["mid", 3]] @@ -68,6 +71,7 @@ export const empty: () => Trie = TR.empty * // The entries in the `Trie` are extracted in alphabetical order, regardless of the insertion order * assert.deepStrictEqual(Array.from(trie), [["call", 0], ["me", 1], ["mid", 3], ["mind", 2]]) * assert.equal(Equal.equals(Trie.make(["call", 0], ["me", 1], ["mind", 2], ["mid", 3]), trie), true) + * ``` * * @since 2.0.0 * @category constructors @@ -78,12 +82,14 @@ export const fromIterable: (entries: Iterable) => Trie< * Constructs a new `Trie` from the specified entries (`[string, V]`). * * @example + * ```ts * import { Trie, Equal } from "effect" * * const trie = Trie.make(["ca", 0], ["me", 1]) * * assert.deepStrictEqual(Array.from(trie), [["ca", 0], ["me", 1]]) * assert.equal(Equal.equals(Trie.fromIterable([["ca", 0], ["me", 1]]), trie), true) + * ``` * * @since 2.0.0 * @category constructors @@ -96,6 +102,7 @@ export const make: >( * Insert a new entry in the `Trie`. * * @example + * ```ts * import { Trie } from "effect" * * const trie1 = Trie.empty().pipe( @@ -109,6 +116,7 @@ export const make: >( * assert.deepStrictEqual(Array.from(trie2), [["call", 0], ["me", 1]]) * assert.deepStrictEqual(Array.from(trie3), [["call", 0], ["me", 1], ["mind", 2]]) * assert.deepStrictEqual(Array.from(trie4), [["call", 0], ["me", 1], ["mid", 3], ["mind", 2]]) + * ``` * * @since 2.0.0 * @category mutations @@ -124,6 +132,7 @@ export const insert: { * The keys are returned in alphabetical order, regardless of insertion order. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -134,6 +143,7 @@ export const insert: { * * const result = Array.from(Trie.keys(trie)) * assert.deepStrictEqual(result, ["abc", "bca", "cab"]) + * ``` * * @since 2.0.0 * @category getters @@ -146,6 +156,7 @@ export const keys: (self: Trie) => IterableIterator = TR.keys * Values are ordered based on their key in alphabetical order, regardless of insertion order. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -156,6 +167,7 @@ export const keys: (self: Trie) => IterableIterator = TR.keys * * const result = Array.from(Trie.values(trie)) * assert.deepStrictEqual(result, [2, 0, 1]) + * ``` * * @since 2.0.0 * @category getters @@ -168,6 +180,7 @@ export const values: (self: Trie) => IterableIterator = TR.values * The entries are returned by keys in alphabetical order, regardless of insertion order. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -177,6 +190,7 @@ export const values: (self: Trie) => IterableIterator = TR.values * * const result = Array.from(Trie.entries(trie)) * assert.deepStrictEqual(result, [["call", 0], ["me", 1]]) + * ``` * * @since 2.0.0 * @category getters @@ -189,6 +203,7 @@ export const entries: (self: Trie) => IterableIterator<[string, V]> = TR.e * Equivalent to `Array.from(Trie.entries(trie))`. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -198,6 +213,7 @@ export const entries: (self: Trie) => IterableIterator<[string, V]> = TR.e * const result = Trie.toEntries(trie) * * assert.deepStrictEqual(result, [["call", 0], ["me", 1]]) + * ``` * * @since 2.0.0 * @category getters @@ -209,6 +225,7 @@ export const toEntries = (self: Trie): Array<[string, V]> => Array.from(en * that have `prefix` as prefix (`prefix` included if it exists). * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -220,6 +237,7 @@ export const toEntries = (self: Trie): Array<[string, V]> => Array.from(en * * const result = Array.from(Trie.keysWithPrefix(trie, "she")) * assert.deepStrictEqual(result, ["she", "shells"]) + * ``` * * @since 2.0.0 * @category getters @@ -234,6 +252,7 @@ export const keysWithPrefix: { * that have `prefix` as prefix (`prefix` included if it exists). * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -247,6 +266,7 @@ export const keysWithPrefix: { * * // 0: "she", 1: "shells" * assert.deepStrictEqual(result, [0, 1]) + * ``` * * @since 2.0.0 * @category getters @@ -261,6 +281,7 @@ export const valuesWithPrefix: { * that have `prefix` as prefix (`prefix` included if it exists). * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -272,6 +293,7 @@ export const valuesWithPrefix: { * * const result = Array.from(Trie.entriesWithPrefix(trie, "she")) * assert.deepStrictEqual(result, [["she", 0], ["shells", 1]]) + * ``` * * @since 2.0.0 * @category getters @@ -286,6 +308,7 @@ export const entriesWithPrefix: { * that have `prefix` as prefix (`prefix` included if it exists). * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -297,6 +320,7 @@ export const entriesWithPrefix: { * * const result = Trie.toEntriesWithPrefix(trie, "she") * assert.deepStrictEqual(result, [["she", 3], ["shells", 0]]) + * ``` * * @since 2.0.0 * @category getters @@ -311,6 +335,7 @@ export const toEntriesWithPrefix: { * that is a prefix of that `key` if it exists, `None` otherwise. * * @example + * ```ts * import { Trie, Option } from "effect" * * const trie = Trie.empty().pipe( @@ -323,6 +348,7 @@ export const toEntriesWithPrefix: { * assert.deepStrictEqual(Trie.longestPrefixOf(trie, "sells"), Option.some(["sells", 1])) * assert.deepStrictEqual(Trie.longestPrefixOf(trie, "shell"), Option.some(["she", 2])) * assert.deepStrictEqual(Trie.longestPrefixOf(trie, "shellsort"), Option.some(["shells", 0])) + * ``` * * @since 2.0.0 * @category getters @@ -336,6 +362,7 @@ export const longestPrefixOf: { * Returns the size of the `Trie` (number of entries in the `Trie`). * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -344,6 +371,7 @@ export const longestPrefixOf: { * ) * * assert.equal(Trie.size(trie), 2) + * ``` * * @since 2.0.0 * @category getters @@ -354,6 +382,7 @@ export const size: (self: Trie) => number = TR.size * Safely lookup the value for the specified key in the `Trie`. * * @example + * ```ts * import { Trie, Option } from "effect" * * const trie = Trie.empty().pipe( @@ -371,6 +400,7 @@ export const size: (self: Trie) => number = TR.size * assert.deepStrictEqual(Trie.get(trie, "ma"), Option.none()) * assert.deepStrictEqual(Trie.get(trie, "midn"), Option.none()) * assert.deepStrictEqual(Trie.get(trie, "mea"), Option.none()) + * ``` * * @since 2.0.0 * @category elements @@ -384,6 +414,7 @@ export const get: { * Check if the given key exists in the `Trie`. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -401,6 +432,7 @@ export const get: { * assert.equal(Trie.has(trie, "ma"), false) * assert.equal(Trie.has(trie, "midn"), false) * assert.equal(Trie.has(trie, "mea"), false) + * ``` * * @since 2.0.0 * @category elements @@ -414,6 +446,7 @@ export const has: { * Checks if the `Trie` contains any entries. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty() @@ -421,6 +454,7 @@ export const has: { * * assert.equal(Trie.isEmpty(trie), true) * assert.equal(Trie.isEmpty(trie1), false) + * ``` * * @since 2.0.0 * @category elements @@ -434,6 +468,7 @@ export const isEmpty: (self: Trie) => boolean = TR.isEmpty * get a value from the `Trie`. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -442,6 +477,7 @@ export const isEmpty: (self: Trie) => boolean = TR.isEmpty * ) * * assert.throws(() => Trie.unsafeGet(trie, "mae")) + * ``` * * @since 2.0.0 * @category unsafe @@ -455,6 +491,7 @@ export const unsafeGet: { * Remove the entry for the specified key in the `Trie`. * * @example + * ```ts * import { Trie, Option } from "effect" * * const trie = Trie.empty().pipe( @@ -470,6 +507,7 @@ export const unsafeGet: { * assert.deepStrictEqual(Trie.get(trie, "call"), Option.some(0)) * assert.deepStrictEqual(Trie.get(trie1, "call"), Option.none()) * assert.deepStrictEqual(Trie.get(trie2, "call"), Option.none()) + * ``` * * @since 2.0.0 * @category mutations @@ -483,6 +521,7 @@ export const remove: { * Reduce a state over the entries of the `Trie`. * * @example + * ```ts * import { Trie } from "effect" * * const trie = Trie.empty().pipe( @@ -509,6 +548,7 @@ export const remove: { * ), * "sellssheshells" * ) + * ``` * * @since 2.0.0 * @category folding @@ -522,6 +562,7 @@ export const reduce: { * Maps over the entries of the `Trie` using the specified function. * * @example + * ```ts * import { Trie, Equal } from "effect" * * const trie = Trie.empty().pipe( @@ -544,6 +585,7 @@ export const reduce: { * * assert.equal(Equal.equals(Trie.map(trie, (v) => v + 1), trieMapV), true) * assert.equal(Equal.equals(Trie.map(trie, (_, k) => k.length), trieMapK), true) + * ``` * * @since 2.0.0 * @category folding @@ -557,6 +599,7 @@ export const map: { * Filters entries out of a `Trie` using the specified predicate. * * @example + * ```ts * import { Trie, Equal } from "effect" * * const trie = Trie.empty().pipe( @@ -576,6 +619,7 @@ export const map: { * * assert.equal(Equal.equals(Trie.filter(trie, (v) => v > 1), trieMapV), true) * assert.equal(Equal.equals(Trie.filter(trie, (_, k) => k.length > 3), trieMapK), true) + * ``` * * @since 2.0.0 * @category filtering @@ -592,6 +636,7 @@ export const filter: { * and filters out `None` values. * * @example + * ```ts * import { Trie, Equal, Option } from "effect" * * const trie = Trie.empty().pipe( @@ -614,6 +659,7 @@ export const filter: { * Equal.equals(Trie.filterMap(trie, (v, k) => k.length > 3 ? Option.some(v) : Option.none()), trieMapK), * true * ) + * ``` * * @since 2.0.0 * @category filtering @@ -627,6 +673,7 @@ export const filterMap: { * Filters out `None` values from a `Trie` of `Options`s. * * @example + * ```ts * import { Trie, Equal, Option } from "effect" * * const trie = Trie.empty>().pipe( @@ -641,6 +688,7 @@ export const filterMap: { * ) * * assert.equal(Equal.equals(Trie.compact(trie), trieMapV), true) + * ``` * * @since 2.0.0 * @category filtering @@ -651,6 +699,7 @@ export const compact: (self: Trie>) => Trie = TR.compact * Applies the specified function to the entries of the `Trie`. * * @example + * ```ts * import { Trie } from "effect" * * let value = 0 @@ -665,6 +714,7 @@ export const compact: (self: Trie>) => Trie = TR.compact * ) * * assert.equal(value, 17) + * ``` * * @since 2.0.0 * @category traversing @@ -678,6 +728,7 @@ export const forEach: { * Updates the value of the specified key within the `Trie` if it exists. * * @example + * ```ts * import { Trie, Equal, Option } from "effect" * * const trie = Trie.empty().pipe( @@ -689,6 +740,7 @@ export const forEach: { * assert.deepStrictEqual(trie.pipe(Trie.modify("she", (v) => v + 10), Trie.get("she")), Option.some(12)) * * assert.equal(Equal.equals(trie.pipe(Trie.modify("me", (v) => v)), trie), true) + * ``` * * @since 2.0.0 * @category mutations @@ -702,6 +754,7 @@ export const modify: { * Removes all entries in the `Trie` which have the specified keys. * * @example + * ```ts * import { Trie, Equal } from "effect" * * const trie = Trie.empty().pipe( @@ -714,6 +767,7 @@ export const modify: { * Equal.equals(trie.pipe(Trie.removeMany(["she", "sells"])), Trie.empty().pipe(Trie.insert("shells", 0))), * true * ) + * ``` * * @since 2.0.0 * @category mutations @@ -727,6 +781,7 @@ export const removeMany: { * Insert multiple entries in the `Trie` at once. * * @example + * ```ts * import { Trie, Equal } from "effect" * * const trie = Trie.empty().pipe( @@ -746,6 +801,7 @@ export const removeMany: { * Equal.equals(trie, trieInsert), * true * ) + * ``` * * @since 2.0.0 * @category mutations diff --git a/packages/effect/src/Tuple.ts b/packages/effect/src/Tuple.ts index 6b3dccc041f..696b73d8ddd 100644 --- a/packages/effect/src/Tuple.ts +++ b/packages/effect/src/Tuple.ts @@ -23,9 +23,11 @@ export interface TupleTypeLambda extends TypeLambda { * @param elements - The list of elements to create the tuple from. * * @example + * ```ts * import { make } from "effect/Tuple" * * assert.deepStrictEqual(make(1, 'hello', true), [1, 'hello', true]) + * ``` * * @category constructors * @since 2.0.0 @@ -38,9 +40,11 @@ export const make = >(...elements: A): A => element * @param self - A tuple of length `2`. * * @example + * ```ts * import { getFirst } from "effect/Tuple" * * assert.deepStrictEqual(getFirst(["hello", 42]), "hello") + * ``` * * @category getters * @since 2.0.0 @@ -53,9 +57,11 @@ export const getFirst = (self: readonly [L, R]): L => self[0] * @param self - A tuple of length `2`. * * @example + * ```ts * import { getSecond } from "effect/Tuple" * * assert.deepStrictEqual(getSecond(["hello", 42]), 42) + * ``` * * @category getters * @since 2.0.0 @@ -69,6 +75,7 @@ export const getSecond = (self: readonly [L, R]): R => self[1] * @param f - The function to transform elements of the tuple. * * @example + * ```ts * import { pipe, Tuple } from "effect" * * const result = pipe( @@ -76,6 +83,7 @@ export const getSecond = (self: readonly [L, R]): R => self[1] * Tuple.map((el) => el.toString().toUpperCase()) * ) * assert.deepStrictEqual(result, ['A', '1', 'FALSE']) + * ``` * * @category mapping * @since 3.9.0 @@ -104,12 +112,14 @@ export const map: { * @param g - The function to transform the second element of the tuple. * * @example + * ```ts * import { mapBoth } from "effect/Tuple" * * assert.deepStrictEqual( * mapBoth(["hello", 42], { onFirst: s => s.toUpperCase(), onSecond: n => n.toString() }), * ["HELLO", "42"] * ) + * ``` * * @category mapping * @since 2.0.0 @@ -141,12 +151,14 @@ export const mapBoth: { * @param f - The function to transform the first element of the tuple. * * @example + * ```ts * import { mapFirst } from "effect/Tuple" * * assert.deepStrictEqual( * mapFirst(["hello", 42], s => s.toUpperCase()), * ["HELLO", 42] * ) + * ``` * * @category mapping * @since 2.0.0 @@ -163,12 +175,14 @@ export const mapFirst: { * @param f - The function to transform the second element of the tuple. * * @example + * ```ts * import { mapSecond } from "effect/Tuple" * * assert.deepStrictEqual( * mapSecond(["hello", 42], n => n.toString()), * ["hello", "42"] * ) + * ``` * * @category mapping * @since 2.0.0 @@ -184,9 +198,11 @@ export const mapSecond: { * @param self - A tuple of length `2`. * * @example + * ```ts * import { swap } from "effect/Tuple" * * assert.deepStrictEqual(swap(["hello", 42]), [42, "hello"]) + * ``` * * @since 2.0.0 */ @@ -236,9 +252,11 @@ export const appendElement: { * @param index - The index of the element to retrieve. * * @example + * ```ts * import { Tuple } from "effect" * * assert.deepStrictEqual(Tuple.at([1, 'hello', true], 1), 'hello') + * ``` * * @category getters * @since 3.4.0 @@ -258,6 +276,7 @@ export { * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`. * * @example + * ```ts * import { isTupleOf } from "effect/Tuple" * * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true); @@ -270,6 +289,7 @@ export { * // ^? [number, number, number] * } * + * ``` * @category guards * @since 3.3.0 */ @@ -283,6 +303,7 @@ export { * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`. * * @example + * ```ts * import { isTupleOfAtLeast } from "effect/Tuple" * * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true); @@ -295,6 +316,7 @@ export { * // ^? [number, number, number, ...number[]] * } * + * ``` * @category guards * @since 3.3.0 */ diff --git a/packages/effect/src/Types.ts b/packages/effect/src/Types.ts index 2785fade80c..95659c54bad 100644 --- a/packages/effect/src/Types.ts +++ b/packages/effect/src/Types.ts @@ -15,6 +15,7 @@ type _TupleOf> = R["length"] exten * @typeParam T - The type of elements in the tuple. * * @example + * ```ts * import { TupleOf } from "effect/Types" * * // A tuple with exactly 3 numbers @@ -23,6 +24,7 @@ type _TupleOf> = R["length"] exten * const example2: TupleOf<3, number> = [1, 2]; // invalid * // @ts-expect-error * const example3: TupleOf<3, number> = [1, 2, 3, 4]; // invalid + * ``` * * @category tuples * @since 3.3.0 @@ -39,6 +41,7 @@ export type TupleOf = N extends N ? number extends N ? Arra * @typeParam T - The type of elements in the tuple. * * @example + * ```ts * import { TupleOfAtLeast } from "effect/Types" * * // A tuple with at least 3 numbers @@ -46,6 +49,7 @@ export type TupleOf = N extends N ? number extends N ? Arra * const example2: TupleOfAtLeast<3, number> = [1, 2, 3, 4, 5]; // valid * // @ts-expect-error * const example3: TupleOfAtLeast<3, number> = [1, 2]; // invalid + * ``` * * @category tuples * @since 3.3.0 @@ -55,9 +59,11 @@ export type TupleOfAtLeast = [...TupleOf, ...Array /** * Returns the tags in a type. * @example + * ```ts * import type { Types } from "effect" * * type Res = Types.Tags // "a" | "b" + * ``` * * @category types * @since 2.0.0 @@ -67,9 +73,11 @@ export type Tags = E extends { _tag: string } ? E["_tag"] : never /** * Excludes the tagged object from the type. * @example + * ```ts * import type { Types } from "effect" * * type Res = Types.ExcludeTag // string | { _tag: "b" } + * ``` * * @category types * @since 2.0.0 @@ -80,9 +88,11 @@ export type ExcludeTag> = Exclude * Extracts the type of the given tag. * * @example + * ```ts * import type { Types } from "effect" * * type Res = Types.ExtractTag<{ _tag: "a", a: number } | { _tag: "b", b: number }, "b"> // { _tag: "b", b: number } + * ``` * * @category types * @since 2.0.0 @@ -102,9 +112,11 @@ export type UnionToIntersection = (T extends any ? (x: T) => any : never) ext * Simplifies the type signature of a type. * * @example + * ```ts * import type { Types } from "effect" * * type Res = Types.Simplify<{ a: number } & { b: number }> // { a: number; b: number; } + * ``` * * @since 2.0.0 * @category types @@ -117,10 +129,12 @@ export type Simplify = { * Determines if two types are equal. * * @example + * ```ts * import type { Types } from "effect" * * type Res1 = Types.Equals<{ a: number }, { a: number }> // true * type Res2 = Types.Equals<{ a: number }, { b: number }> // false + * ``` * * @since 2.0.0 * @category models @@ -134,10 +148,12 @@ export type Equals = (() => T extends X ? 1 : 2) extends < * Determines if a record contains any of the given keys. * * @example + * ```ts * import type { Types } from "effect" * * type Res1 = Types.Has<{ a: number }, "a" | "b"> // true * type Res2 = Types.Has<{ c: number }, "a" | "b"> // false + * ``` * * @since 2.0.0 * @category models @@ -150,8 +166,10 @@ export type Has = (Key extends infer K ? K extends keyof * Merges two object where the keys of the left object take precedence in the case of a conflict. * * @example + * ```ts * import type { Types } from "effect" * type MergeLeft = Types.MergeLeft<{ a: number, b: number; }, { a: string }> // { a: number; b: number; } + * ``` * * @since 2.0.0 * @category models @@ -162,8 +180,10 @@ export type MergeLeft = MergeRight * Merges two object where the keys of the right object take precedence in the case of a conflict. * * @example + * ```ts * import type { Types } from "effect" * type MergeRight = Types.MergeRight<{ a: number, b: number; }, { a: string }> // { a: string; b: number; } + * ``` * * @since 2.0.0 * @category models @@ -193,6 +213,7 @@ export type Concurrency = number | "unbounded" | "inherit" * Make all properties in `T` mutable. Supports arrays, tuples, and records as well. * * @example + * ```ts * import type { Types } from "effect" * * type MutableStruct = Types.Mutable<{ readonly a: string; readonly b: number }> // { a: string; b: number; } @@ -202,6 +223,7 @@ export type Concurrency = number | "unbounded" | "inherit" * type MutableTuple = Types.Mutable // [string, number] * * type MutableRecord = Types.Mutable<{ readonly [_: string]: number }> // { [x: string]: number; } + * ``` * * @since 2.0.0 * @category types @@ -214,6 +236,7 @@ export type Mutable = { * Like `Types.Mutable`, but works recursively. * * @example + * ```ts * import type { Types } from "effect" * * type DeepMutableStruct = Types.DeepMutable<{ @@ -221,6 +244,7 @@ export type Mutable = { * readonly b: readonly string[] * }> * // { a: string; b: string[] } + * ``` * * @since 3.1.0 * @category types diff --git a/packages/experimental/src/Machine.ts b/packages/experimental/src/Machine.ts index ae155e17d89..0e4b8c72b55 100644 --- a/packages/experimental/src/Machine.ts +++ b/packages/experimental/src/Machine.ts @@ -408,19 +408,19 @@ export const makeSerializable: { initialize: | Machine.InitializeSerializable | Effect.Effect, InitErr, R> -): SerializableMachine, RS | RI> => - ({ - [TypeId]: TypeId, - [SerializableTypeId]: SerializableTypeId, - initialize: Effect.isEffect(initialize) ? (() => initialize) : initialize as any, - identifier: "SerializableMachine", - retryPolicy: undefined, - schemaInput: options.input as any, - schemaState: options.state as any, - pipe() { - return pipeArguments(this, arguments) - } - }) as any +): SerializableMachine, RS | RI> => (({ + [TypeId]: TypeId, + [SerializableTypeId]: SerializableTypeId, + initialize: Effect.isEffect(initialize) ? (() => initialize) : initialize as any, + identifier: "SerializableMachine", + retryPolicy: undefined, + schemaInput: options.input as any, + schemaState: options.state as any, + + pipe() { + return pipeArguments(this, arguments) + } +}) as any) /** * @since 1.0.0 @@ -437,11 +437,10 @@ export const retry: { } = dual(2, | MachineDefect, R>( self: M, retryPolicy: Schedule.Schedule -): Machine.AddContext => - ({ - ...self, - retryPolicy - }) as any) +): Machine.AddContext => (({ + ...self, + retryPolicy +}) as any)) /** * @since 1.0.0 diff --git a/packages/platform-node/src/NodeHttpServer.ts b/packages/platform-node/src/NodeHttpServer.ts index 5547a9fa995..1f0a6dc937c 100644 --- a/packages/platform-node/src/NodeHttpServer.ts +++ b/packages/platform-node/src/NodeHttpServer.ts @@ -91,6 +91,7 @@ export const layerConfig: ( * with prepended url of the running http server. * * @example + * ```ts * import { HttpClient, HttpRouter, HttpServer } from "@effect/platform" * import { NodeHttpServer } from "@effect/platform-node" * import { Effect } from "effect" @@ -100,6 +101,7 @@ export const layerConfig: ( * const response = yield* HttpClient.get("/") * assert.strictEqual(response.status, 404) * }).pipe(Effect.provide(NodeHttpServer.layerTest)) + * ``` * * @since 1.0.0 * @category layers diff --git a/packages/platform/src/HttpApiBuilder.ts b/packages/platform/src/HttpApiBuilder.ts index 36f07d35270..73096bf4d59 100644 --- a/packages/platform/src/HttpApiBuilder.ts +++ b/packages/platform/src/HttpApiBuilder.ts @@ -126,6 +126,7 @@ export const httpApp: Effect.Effect< * @since 1.0.0 * @category constructors * @example + * ```ts * import { HttpApi, HttpApiBuilder, HttpServer } from "@effect/platform" * import { Layer } from "effect" * @@ -141,6 +142,7 @@ export const httpApp: Effect.Effect< * HttpServer.layerContext * ) * ) + * ``` */ export const toWebHandler = ( layer: Layer.Layer, diff --git a/packages/platform/src/PlatformLogger.ts b/packages/platform/src/PlatformLogger.ts index bad005b2203..425713a7f4f 100644 --- a/packages/platform/src/PlatformLogger.ts +++ b/packages/platform/src/PlatformLogger.ts @@ -14,6 +14,7 @@ import * as internal from "./internal/platformLogger.js" * * @since 1.0.0 * @example + * ```ts * import { PlatformLogger } from "@effect/platform" * import { NodeFileSystem, NodeRuntime } from "@effect/platform-node" * import { Effect, Layer, Logger } from "effect" @@ -31,6 +32,7 @@ import * as internal from "./internal/platformLogger.js" * Effect.provide(LoggerLive), * NodeRuntime.runMain * ) + * ``` */ export const toFile: { ( diff --git a/packages/printer/src/Doc.ts b/packages/printer/src/Doc.ts index 4073d9d34b2..4ab88fa59b8 100644 --- a/packages/printer/src/Doc.ts +++ b/packages/printer/src/Doc.ts @@ -472,6 +472,7 @@ export const string: (str: string) => Doc = internal.string * render an empty line of output. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -490,6 +491,7 @@ export const string: (str: string) => Doc = internal.string * Doc.render(doc, { style: "pretty" }), * String.stripMargin(expected) * ) + * ``` * * @since 1.0.0 * @category primitives @@ -513,6 +515,7 @@ export const fail: Doc = internal.fail * undone by `group`. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -533,6 +536,7 @@ export const fail: Doc = internal.fail * Doc.render(Doc.group(doc), { style: "pretty" }), * "lorem ipsum dolor sit amet" * ) + * ``` * * @since 1.0.0 * @category primitives @@ -544,6 +548,7 @@ export const line: Doc = internal.line * break is undone by `group` (instead of `space`). * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -564,6 +569,7 @@ export const line: Doc = internal.line * Doc.render(Doc.group(doc), { style: "pretty" }), * "lorem ipsumdolor sit amet" * ) + * ``` * * @since 1.0.0 * @category primitives @@ -575,6 +581,7 @@ export const lineBreak: Doc = internal.lineBreak * onto the page, otherwise it behaves like `line`. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -605,6 +612,7 @@ export const lineBreak: Doc = internal.lineBreak * |dolor sit amet` * ) * ) + * ``` * * @since 1.0.0 * @category primitives @@ -617,6 +625,7 @@ export const softLine: Doc = internal.softLine * `space`). * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -647,6 +656,7 @@ export const softLine: Doc = internal.softLine * |IsWayTooLong` * ) * ) + * ``` * * @since 1.0.0 * @category primitives @@ -658,6 +668,7 @@ export const softLineBreak: Doc = internal.softLineBreak * space or whether or not the document was `group`"ed. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -678,6 +689,7 @@ export const softLineBreak: Doc = internal.softLineBreak * |dolor sit amet` * ) * ) + * ``` * * @since 1.0.0 * @category primitives @@ -858,6 +870,7 @@ export const cat: { * which always lays out documents beneath one another. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -884,6 +897,7 @@ export const cat: { * |dolor` * ) * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -895,6 +909,7 @@ export const cats: (docs: Iterable>) => Doc = internal.cats * document between them. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -911,6 +926,7 @@ export const cats: (docs: Iterable>) => Doc = internal.cats * |b` * ) * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -925,6 +941,7 @@ export const catWithLine: { * `lineBreak` document between them. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -946,6 +963,7 @@ export const catWithLine: { * Doc.render(Doc.group(doc), { style: "pretty" }), * "ab" * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -960,6 +978,7 @@ export const catWithLineBreak: { * `softLine` document between them. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -984,6 +1003,7 @@ export const catWithLineBreak: { * |b` * ) * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -998,6 +1018,7 @@ export const catWithSoftLine: { * placing a `softLineBreak` document between them. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1022,6 +1043,7 @@ export const catWithSoftLine: { * |b` * ) * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -1036,6 +1058,7 @@ export const catWithSoftLineBreak: { * `space` document between them. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * @@ -1048,6 +1071,7 @@ export const catWithSoftLineBreak: { * Doc.render(doc, { style: "pretty" }), * "a b" * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -1062,6 +1086,7 @@ export const catWithSpace: { * element-wise with the specified binary function. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * @@ -1074,6 +1099,7 @@ export const catWithSpace: { * Doc.render(doc, { style: "pretty" }), * "a b" * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -1091,6 +1117,7 @@ export const concatWith: { * replaced by spaces. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1104,6 +1131,7 @@ export const concatWith: { * |dolor` * ) * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -1115,6 +1143,7 @@ export const vcat: (docs: Iterable>) => Doc = internal.vcat * without any spacing. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1124,6 +1153,7 @@ export const vcat: (docs: Iterable>) => Doc = internal.vcat * Doc.render(doc, { style: "pretty" }), * "loremipsumdolor" * ) + * ``` * * @since 1.0.0 * @category concatenation @@ -1156,6 +1186,7 @@ export const fillCat: (docs: Iterable>) => Doc = internal.fillCat * For automatic line breaks, consider using `fillSep`. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * * const doc: Doc.Doc = Doc.hsep(Doc.words("lorem ipsum dolor sit amet")) @@ -1177,6 +1208,7 @@ export const fillCat: (docs: Iterable>) => Doc = internal.fillCat * }), * "lorem ipsum dolor sit amet" * ) + * ``` * * @since 1.0.0 * @category separation @@ -1193,6 +1225,7 @@ export const hsep: (docs: Iterable>) => Doc = internal.hsep * function for this use case. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1227,6 +1260,7 @@ export const hsep: (docs: Iterable>) => Doc = internal.hsep * | out` * ) * ) + * ``` * * @since 1.0.0 * @category separation @@ -1255,6 +1289,7 @@ export const fillSep: (docs: Iterable>) => Doc = internal.fillSep * `vsep`, which always lays out documents beneath one another. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1281,6 +1316,7 @@ export const fillSep: (docs: Iterable>) => Doc = internal.fillSep * |out` * ) * ) + * ``` * * @since 1.0.0 * @category separation @@ -1302,6 +1338,7 @@ export const seps: (docs: Iterable>) => Doc = internal.seps * algorithms will fall back to an even wider layout. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1357,6 +1394,7 @@ export const seps: (docs: Iterable>) => Doc = internal.seps * | putStrLn greet` * ) * ) + * ``` * * @since 1.0.0 * @category alternative layouts @@ -1396,6 +1434,7 @@ export const group: (self: Doc) => Doc = internal.group * Lays out a document depending upon the column at which the document starts. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1425,6 +1464,7 @@ export const group: (self: Doc) => Doc = internal.group * | prefix | <- column 15` * ) * ) + * ``` * * @since 1.0.0 * @category reactive layouts @@ -1436,6 +1476,7 @@ export const column: (react: (position: number) => Doc) => Doc = intern * current indentation of the document). * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1454,6 +1495,7 @@ export const column: (react: (position: number) => Doc) => Doc = intern * | prefix [Nested: 8]` * ) * ) + * ``` * * @since 1.0.0 * @category reactive layouts @@ -1465,6 +1507,7 @@ export const nesting: (react: (level: number) => Doc) => Doc = internal * document while rendering. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1494,6 +1537,7 @@ export const nesting: (react: (level: number) => Doc) => Doc = internal * | ---] <- width: 8` * ) * ) + * ``` * * @since 1.0.0 * @category reactive layouts @@ -1507,6 +1551,7 @@ export const width: { * Lays out a document according to the document"s`PageWidth`. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1540,6 +1585,7 @@ export const width: { * | prefix [Width: 32, Ribbon Fraction: 1]` * ) * ) + * ``` * * @since 1.0.0 * @category constructors @@ -1565,6 +1611,7 @@ export const pageWidth: (react: (pageWidth: PageWidth) => Doc) => Doc = * any empty space with spaces * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1585,6 +1632,7 @@ export const pageWidth: (react: (pageWidth: PageWidth) => Doc) => Doc = * |amet` * ) * ) + * ``` * * @since 1.0.0 * @category alignment @@ -1599,6 +1647,7 @@ export const nest: { * current column. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -1633,6 +1682,7 @@ export const nest: { * | dolor` * ) * ) + * ``` * * @since 1.0.0 * @category alignment @@ -1649,6 +1699,7 @@ export const align: (self: Doc) => Doc = internal.align * more efficient combinator (`nest`) first. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1669,6 +1720,7 @@ export const align: (self: Doc) => Doc = internal.align * | hang` * ) * ) + * ``` * * @since 1.0.0 * @category alignment @@ -1683,6 +1735,7 @@ export const hang: { * beginning from the current cursor position. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1704,6 +1757,7 @@ export const hang: { * | words!` * ) * ) + * ``` * * @since 1.0.0 * @category alignment @@ -1723,6 +1777,7 @@ export const indent: { * combinator. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1758,6 +1813,7 @@ export const indent: { * | ,4000]` * ) * ) + * ``` * * @since 1.0.0 * @category alignment @@ -1776,6 +1832,7 @@ export const encloseSep: { * and braces as the enclosure for a collection of documents. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * * const doc = Doc.list( @@ -1788,6 +1845,7 @@ export const encloseSep: { * Doc.render(doc, { style: "pretty" }), * "[1, 20, 300, 4000]" * ) + * ``` * * @since 1.0.0 * @category alignment @@ -1799,6 +1857,7 @@ export const list: (docs: Iterable>) => Doc = internal.list * and parentheses as the enclosure for a collection of documents. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * * const doc = Doc.tupled( @@ -1811,6 +1870,7 @@ export const list: (docs: Iterable>) => Doc = internal.list * Doc.render(doc, { style: "pretty" }), * "(1, 20, 300, 4000)" * ) + * ``` * * @since 1.0.0 * @category alignment @@ -1828,6 +1888,7 @@ export const tupled: (docs: Iterable>) => Doc = internal.tupled * appended. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1860,6 +1921,7 @@ export const tupled: (docs: Iterable>) => Doc = internal.tupled * | fillSep :: [Doc] -> Doc` * ) * ) + * ``` * * @since 1.0.0 * @category filling @@ -1876,6 +1938,7 @@ export const fill: { * level is increased by the specified `width` and a `line` is appended. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -1909,6 +1972,7 @@ export const fill: { * | :: [Doc] -> Doc` * ) * ) + * ``` * * @since 1.0.0 * @category filling @@ -2135,6 +2199,7 @@ export const Invariant: invariant.Invariant = internal.Invariant * documents. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * @@ -2147,6 +2212,7 @@ export const Invariant: invariant.Invariant = internal.Invariant * Doc.render(doc, { style: "pretty" }), * "A-Z" * ) + * ``` * * @since 1.0.0 * @category utilities @@ -2209,6 +2275,7 @@ export const curlyBraced: (self: Doc) => Doc = internal.curlyBraced * values for `n` count as `0` spaces. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * * const doc = Doc.squareBracketed(Doc.doubleQuoted(Doc.spaces(5))) @@ -2217,6 +2284,7 @@ export const curlyBraced: (self: Doc) => Doc = internal.curlyBraced * Doc.render(doc, { style: "pretty" }), * "[\" \"]" * ) + * ``` * * @since 1.0.0 * @category utilities @@ -2234,6 +2302,7 @@ export const textSpaces: (n: number) => string = internal.textSpaces * specified `char` to split on (defaults to `" "`). * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * * const doc = Doc.tupled(Doc.words("lorem ipsum dolor")) @@ -2242,6 +2311,7 @@ export const textSpaces: (n: number) => string = internal.textSpaces * Doc.render(doc, { style: "pretty" }), * "(lorem, ipsum, dolor)" * ) + * ``` * * @since 1.0.0 * @category utilities @@ -2255,6 +2325,7 @@ export const words: (s: string, char?: string) => ReadonlyArray> = in * be broken into multiple lines. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as String from "effect/String" * @@ -2276,6 +2347,7 @@ export const words: (s: string, char?: string) => ReadonlyArray> = in * |aliqua.` * ) * ) + * ``` * * @since 1.0.0 * @category utilities @@ -2289,6 +2361,7 @@ export const reflow: (s: string, char?: string) => Doc = internal.reflow * vertically. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import { pipe } from "effect/Function" * import * as String from "effect/String" @@ -2315,6 +2388,7 @@ export const reflow: (s: string, char?: string) => Doc = internal.reflow * |amet` * ) * ) + * ``` * * @since 1.0.0 * @category utilities diff --git a/packages/printer/src/DocTree.ts b/packages/printer/src/DocTree.ts index c55b7e0689a..86a33a4e9e9 100644 --- a/packages/printer/src/DocTree.ts +++ b/packages/printer/src/DocTree.ts @@ -296,6 +296,7 @@ export const foldMap: { * to surround annotated regions with »>>>« and »<<<«. * * @example + * ```ts * import * as Doc from "@effect/printer/Doc" * import * as DocTree from "@effect/printer/DocTree" * import * as Layout from "@effect/printer/Layout" @@ -322,6 +323,7 @@ export const foldMap: { * rendered, * "hello >>>world<< NodeStream.Duplex) | undefined @@ -108,10 +110,12 @@ export interface PgClientConfig { * By default, postgres.js logs these with console.log. * To silence notices, see the following example: * @example + * ```ts * import { PgClient } from "@effect/sql-pg"; * import { Config, Layer } from "effect" * * const layer = PgClient.layer({ onnotice: Config.succeed(() => {}) }) + * ``` */ readonly onnotice?: (notice: postgres.Notice) => void readonly types?: Record | undefined diff --git a/packages/sql/src/Model.ts b/packages/sql/src/Model.ts index 5b4280a2c30..c7850155f50 100644 --- a/packages/sql/src/Model.ts +++ b/packages/sql/src/Model.ts @@ -77,6 +77,7 @@ export { * @since 1.0.0 * @category constructors * @example + * ```ts * import { Schema } from "effect" * import { Model } from "@effect/sql" * @@ -109,6 +110,7 @@ export { * return this.name.toUpperCase() * } * } + * ``` */ Class, /** diff --git a/packages/typeclass/src/Covariant.ts b/packages/typeclass/src/Covariant.ts index fc214d58f71..b7629fb7fbd 100644 --- a/packages/typeclass/src/Covariant.ts +++ b/packages/typeclass/src/Covariant.ts @@ -98,6 +98,7 @@ const let_ = ( export { /** * @example + * ```ts * import * as covariant from "@effect/typeclass/Covariant" * import type { HKT } from "effect" * import { dual, pipe } from "effect/Function" @@ -124,6 +125,7 @@ export { * * assert.deepStrictEqual(pipe(notation.Do, notation.let("foo", () => "bar")), { value: { foo: "bar" } }) * + * ``` * @category do notation * @since 0.24.0 */ diff --git a/packages/typeclass/src/data/BigInt.ts b/packages/typeclass/src/data/BigInt.ts index 52012851662..be7104865e0 100644 --- a/packages/typeclass/src/data/BigInt.ts +++ b/packages/typeclass/src/data/BigInt.ts @@ -10,9 +10,11 @@ import * as semigroup from "../Semigroup.js" * `bigint` semigroup under addition. * * @example + * ```ts * import { SemigroupSum } from "@effect/typeclass/data/BigInt" * * assert.deepStrictEqual(SemigroupSum.combine(2n, 3n), 5n) + * ``` * * @category instances * @since 0.24.0 @@ -48,9 +50,11 @@ export const SemigroupMultiply: semigroup.Semigroup = semigroup.make( * A `Semigroup` that uses the minimum between two values. * * @example + * ```ts * import { SemigroupMin } from "@effect/typeclass/data/BigInt" * * assert.deepStrictEqual(SemigroupMin.combine(2n, 3n), 2n) + * ``` * * @category instances * @since 0.24.0 @@ -61,9 +65,11 @@ export const SemigroupMin: semigroup.Semigroup = semigroup.min(Order) * A `Semigroup` that uses the maximum between two values. * * @example + * ```ts * import { SemigroupMax } from "@effect/typeclass/data/BigInt" * * assert.deepStrictEqual(SemigroupMax.combine(2n, 3n), 3n) + * ``` * * @category instances * @since 0.24.0 @@ -76,10 +82,12 @@ export const SemigroupMax: semigroup.Semigroup = semigroup.max(Order) * The `empty` value is `0n`. * * @example + * ```ts * import { MonoidSum } from "@effect/typeclass/data/BigInt" * * assert.deepStrictEqual(MonoidSum.combine(2n, 3n), 5n) * assert.deepStrictEqual(MonoidSum.combine(2n, MonoidSum.empty), 2n) + * ``` * * @category instances * @since 0.24.0 @@ -95,10 +103,12 @@ export const MonoidSum: monoid.Monoid = monoid.fromSemigroup( * The `empty` value is `1n`. * * @example + * ```ts * import { MonoidMultiply } from "@effect/typeclass/data/BigInt" * * assert.deepStrictEqual(MonoidMultiply.combine(2n, 3n), 6n) * assert.deepStrictEqual(MonoidMultiply.combine(2n, MonoidMultiply.empty), 2n) + * ``` * * @category instances * @since 0.24.0 diff --git a/packages/typeclass/src/data/Boolean.ts b/packages/typeclass/src/data/Boolean.ts index 4f848ec6cbc..f7b508428c2 100644 --- a/packages/typeclass/src/data/Boolean.ts +++ b/packages/typeclass/src/data/Boolean.ts @@ -8,12 +8,14 @@ import * as semigroup from "../Semigroup.js" * `boolean` semigroup under conjunction. * * @example + * ```ts * import { SemigroupEvery } from "@effect/typeclass/data/Boolean" * * assert.deepStrictEqual(SemigroupEvery.combine(true, true), true) * assert.deepStrictEqual(SemigroupEvery.combine(true, false), false) * assert.deepStrictEqual(SemigroupEvery.combine(false, true), false) * assert.deepStrictEqual(SemigroupEvery.combine(false, false), false) + * ``` * * @category instances * @since 0.24.0 @@ -37,12 +39,14 @@ export const SemigroupEvery: semigroup.Semigroup = semigroup.make( * `boolean` semigroup under disjunction. * * @example + * ```ts * import { SemigroupSome } from "@effect/typeclass/data/Boolean" * * assert.deepStrictEqual(SemigroupSome.combine(true, true), true) * assert.deepStrictEqual(SemigroupSome.combine(true, false), true) * assert.deepStrictEqual(SemigroupSome.combine(false, true), true) * assert.deepStrictEqual(SemigroupSome.combine(false, false), false) + * ``` * * @category instances * @since 0.24.0 @@ -66,12 +70,14 @@ export const SemigroupSome: semigroup.Semigroup = semigroup.make( * `boolean` semigroup under exclusive disjunction. * * @example + * ```ts * import { SemigroupXor } from "@effect/typeclass/data/Boolean" * * assert.deepStrictEqual(SemigroupXor.combine(true, true), false) * assert.deepStrictEqual(SemigroupXor.combine(true, false), true) * assert.deepStrictEqual(SemigroupXor.combine(false, true), true) * assert.deepStrictEqual(SemigroupXor.combine(false, false), false) + * ``` * * @category instances * @since 0.24.0 @@ -82,12 +88,14 @@ export const SemigroupXor: semigroup.Semigroup = semigroup.make((self, * `boolean` semigroup under equivalence. * * @example + * ```ts * import { SemigroupEqv } from "@effect/typeclass/data/Boolean" * * assert.deepStrictEqual(SemigroupEqv.combine(true, true), true) * assert.deepStrictEqual(SemigroupEqv.combine(true, false), false) * assert.deepStrictEqual(SemigroupEqv.combine(false, true), false) * assert.deepStrictEqual(SemigroupEqv.combine(false, false), true) + * ``` * * @category instances * @since 0.24.0 diff --git a/packages/typeclass/src/data/Number.ts b/packages/typeclass/src/data/Number.ts index 975579d044a..62da7b24eb1 100644 --- a/packages/typeclass/src/data/Number.ts +++ b/packages/typeclass/src/data/Number.ts @@ -20,9 +20,11 @@ export const Bounded: bounded.Bounded = { * `number` semigroup under addition. * * @example + * ```ts * import { SemigroupSum } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(SemigroupSum.combine(2, 3), 5) + * ``` * * @category instances * @since 0.24.0 @@ -33,9 +35,11 @@ export const SemigroupSum: semigroup.Semigroup = semigroup.make((self, t * `number` semigroup under multiplication. * * @example + * ```ts * import { SemigroupMultiply } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(SemigroupMultiply.combine(2, 3), 6) + * ``` * * @category instances * @since 0.24.0 @@ -61,9 +65,11 @@ export const SemigroupMultiply: semigroup.Semigroup = semigroup.make( * A `Semigroup` that uses the minimum between two values. * * @example + * ```ts * import { SemigroupMin } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(SemigroupMin.combine(2, 3), 2) + * ``` * * @category instances * @since 0.24.0 @@ -74,9 +80,11 @@ export const SemigroupMin: semigroup.Semigroup = semigroup.min(Number.Or * A `Semigroup` that uses the maximum between two values. * * @example + * ```ts * import { SemigroupMax } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(SemigroupMax.combine(2, 3), 3) + * ``` * * @category instances * @since 0.24.0 @@ -89,10 +97,12 @@ export const SemigroupMax: semigroup.Semigroup = semigroup.max(Number.Or * The `empty` value is `0`. * * @example + * ```ts * import { MonoidSum } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(MonoidSum.combine(2, 3), 5) * assert.deepStrictEqual(MonoidSum.combine(2, MonoidSum.empty), 2) + * ``` * * @category instances * @since 0.24.0 @@ -105,10 +115,12 @@ export const MonoidSum: monoid.Monoid = monoid.fromSemigroup(SemigroupSu * The `empty` value is `1`. * * @example + * ```ts * import { MonoidMultiply } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(MonoidMultiply.combine(2, 3), 6) * assert.deepStrictEqual(MonoidMultiply.combine(2, MonoidMultiply.empty), 2) + * ``` * * @category instances * @since 0.24.0 @@ -121,10 +133,12 @@ export const MonoidMultiply: monoid.Monoid = monoid.fromSemigroup(Semigr * The `empty` value is `-Infinity`. * * @example + * ```ts * import { MonoidMin } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(MonoidMin.combine(2, 3), 2) * assert.deepStrictEqual(MonoidMin.combine(2, MonoidMin.empty), 2) + * ``` * * @category instances * @since 0.24.0 @@ -137,10 +151,12 @@ export const MonoidMin: monoid.Monoid = bounded.min(Bounded) * The `empty` value is `Infinity`. * * @example + * ```ts * import { MonoidMax } from "@effect/typeclass/data/Number" * * assert.deepStrictEqual(MonoidMax.combine(2, 3), 3) * assert.deepStrictEqual(MonoidMax.combine(2, MonoidMax.empty), 2) + * ``` * * @category instances * @since 0.24.0 diff --git a/packages/typeclass/src/data/Ordering.ts b/packages/typeclass/src/data/Ordering.ts index fe982593dff..936f72b2d74 100644 --- a/packages/typeclass/src/data/Ordering.ts +++ b/packages/typeclass/src/data/Ordering.ts @@ -9,11 +9,13 @@ import * as semigroup from "../Semigroup.js" * `Semigroup` instance for `Ordering`, returns the left-most non-zero `Ordering`. * * @example + * ```ts * import { Semigroup } from "@effect/typeclass/data/Ordering" * * assert.deepStrictEqual(Semigroup.combine(0, -1), -1) * assert.deepStrictEqual(Semigroup.combine(0, 1), 1) * assert.deepStrictEqual(Semigroup.combine(1, -1), 1) + * ``` * * @category instances * @since 0.24.0 @@ -40,11 +42,13 @@ export const Semigroup: semigroup.Semigroup = semigroup.make( * The `empty` value is `0`. * * @example + * ```ts * import { Monoid } from "@effect/typeclass/data/Ordering" * * assert.deepStrictEqual(Monoid.combine(Monoid.empty, -1), -1) * assert.deepStrictEqual(Monoid.combine(Monoid.empty, 1), 1) * assert.deepStrictEqual(Monoid.combine(1, -1), 1) + * ``` * * @category instances * @since 0.24.0 diff --git a/packages/typeclass/src/data/Record.ts b/packages/typeclass/src/data/Record.ts index 1ed1b3b0e54..491a99a3438 100644 --- a/packages/typeclass/src/data/Record.ts +++ b/packages/typeclass/src/data/Record.ts @@ -214,10 +214,12 @@ export const TraversableFilterable = getTraversableFilterable() * For example, when using the `MonoidSum`, values for matching keys will be summed. * * @example + * ```ts * import * as NumberInstances from "@effect/typeclass/data/Number" * import { getSemigroupUnion } from "@effect/typeclass/data/Record" * * assert.deepStrictEqual(getSemigroupUnion(NumberInstances.MonoidSum).combine({ a: 1 }, { a: 1, b: 3 }), { a: 2, b: 3 }) + * ``` * * @category instances * @since 0.29.4 @@ -236,6 +238,7 @@ export const getSemigroupUnion: ( * The `empty` value for this `Monoid` is an empty record `{}`. * * @example + * ```ts * import * as NumberInstances from "@effect/typeclass/data/Number" * import { getMonoidUnion } from "@effect/typeclass/data/Record" * @@ -243,6 +246,7 @@ export const getSemigroupUnion: ( * * assert.deepStrictEqual(monoid.combine({ a: 1 }, { a: 1, b: 3 }), { a: 2, b: 3 }) * assert.deepStrictEqual(monoid.combine({ a: 1 }, monoid.empty), { a: 1 }) + * ``` * * @category instances * @since 0.29.4 @@ -259,10 +263,12 @@ export const getMonoidUnion: ( * The values for matching keys are combined using the provided `Semigroup` instance. * * @example + * ```ts * import * as NumberInstances from "@effect/typeclass/data/Number" * import { getSemigroupIntersection } from "@effect/typeclass/data/Record" * * assert.deepStrictEqual(getSemigroupIntersection(NumberInstances.MonoidSum).combine({ a: 1 }, { a: 1, b: 3 }), { a: 2 }) + * ``` * * @category instances * @since 0.29.4 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ef6cf1d72e..2b16c9134dd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,8 +57,8 @@ importers: specifier: ^0.7.7 version: 0.7.7 '@effect/docgen': - specifier: ^0.4.4 - version: 0.4.4(tsx@4.17.0)(typescript@5.7.2) + specifier: ^0.5.1 + version: 0.5.1(tsx@4.17.0)(typescript@5.7.2) '@effect/dtslint': specifier: ^0.1.2 version: 0.1.2(typescript@5.7.2) @@ -2008,8 +2008,8 @@ packages: engines: {node: '>=16.17.1'} hasBin: true - '@effect/docgen@0.4.4': - resolution: {integrity: sha512-Qk/LzpXH/5zXpTA+JL5ggnuZwNzgUWxdU5m0MV8IrWUGeBkE7s5W8kA4UsQXRrZsu7tVf//J7OGHNZz4wZkBgw==} + '@effect/docgen@0.5.1': + resolution: {integrity: sha512-5TW9X7xomC553EkYI7/m5krxqmh064zjcTNDTKXOWQqodcyb546DvtqSsoGmpNHzXkPjn70tqiM9/hWuoeDNHQ==} engines: {node: '>=18.0.0'} hasBin: true peerDependencies: @@ -9664,7 +9664,7 @@ snapshots: '@effect/build-utils@0.7.7': {} - '@effect/docgen@0.4.4(tsx@4.17.0)(typescript@5.7.2)': + '@effect/docgen@0.5.1(tsx@4.17.0)(typescript@5.7.2)': dependencies: '@effect/markdown-toc': 0.1.0 doctrine: 3.0.0 diff --git a/scripts/codemod-ts-fence.mjs b/scripts/codemod-ts-fence.mjs new file mode 100644 index 00000000000..e9b828205a0 --- /dev/null +++ b/scripts/codemod-ts-fence.mjs @@ -0,0 +1,23 @@ +// @ts-check +import * as Glob from "glob" +import jscodeshift from "jscodeshift/src/Runner.js" +import * as Fs from "node:fs" +import * as Path from "node:path" + +const packageJsonPath = Path.resolve("package.json") +const packageJson = JSON.parse(Fs.readFileSync(packageJsonPath, "utf-8")) +const workspaces = Glob.globSync(packageJson["workspaces"]) +const packages = workspaces.map((workspace) => workspace.replace("packages/", "")) +const pattern = `packages/{${packages.join(",")}}/src/**/*.ts` + +const paths = Glob.globSync(pattern, { + ignore: ["**/internal/**"] +}).map((path) => Path.resolve(path)) + +const transformer = Path.resolve("scripts/codemods/ts-fence.ts") + +jscodeshift.run(transformer, paths, { + babel: true, + parser: "ts" + // dry: true +}) diff --git a/scripts/codemod.mjs b/scripts/codemod.mjs index bdcb0eb22cc..72847fa2407 100644 --- a/scripts/codemod.mjs +++ b/scripts/codemod.mjs @@ -16,7 +16,7 @@ const paths = Glob.globSync(pattern, { const transformer = Path.resolve("scripts/codemods/jsdoc.ts") -jscodeshift.run(Path.resolve(transformer), paths, { +jscodeshift.run(transformer, paths, { babel: true, parser: "ts" }) diff --git a/scripts/codemods/ts-fence.test.ts b/scripts/codemods/ts-fence.test.ts new file mode 100644 index 00000000000..573e01ce92f --- /dev/null +++ b/scripts/codemods/ts-fence.test.ts @@ -0,0 +1,132 @@ +// You can run this test suite with the following command: +// npx vitest scripts/codemods/ts-fence.test.ts --config scripts/codemods/vitest.config.ts +import type cs from "jscodeshift" +import * as TestUtils from "jscodeshift/src/testUtils" +import transformer from "./ts-fence.ts" + +const expectTransformation_ = (transformer: cs.Transform) => +( + description: string, + input: string, + output: string +) => { + TestUtils.defineInlineTest( + { default: transformer, parser: "ts" }, + {}, + input, + output, + description + ) +} + +const expectTransformation = expectTransformation_(transformer) + +expectTransformation( + "should ignore line comments", + `// description +const v = 1`, + `// description +const v = 1` +) + +expectTransformation( + "should ignore block comments that don't contain an @example tag", + ` +/** + * description + */ +const v = 1`, + ` +/** + * description + */ +const v = 1` +) + +expectTransformation( + "should wrap the given code in a ts fence (without following tags)", + ` +/** + * a + * + * b + * + * @example + * const x = 1 + * + */ +const v = 1`, + ` +/** + * a + * + * b + * + * @example + * \`\`\`ts + * const x = 1 + * + * \`\`\` + */ +const v = 1` +) + +expectTransformation( + "should wrap the given code in a ts fence (with following tags)", + ` +/** + * a + * + * b + * + * @example + * const x = 1 + * + * @since 1.0.0 + * @category collecting & elements + */ +const v = 1`, + ` +/** + * a + * + * b + * + * @example + * \`\`\`ts + * const x = 1 + * \`\`\` + * + * @since 1.0.0 + * @category collecting & elements + */ +const v = 1` +) + +expectTransformation( + "should skip wrapping if the code is already in a ts fence", + ` +/** + * a + * + * b + * + * @example + * \`\`\`ts + * const x = 1 + * \`\`\` + */ +const v = 1`, + ` +/** + * a + * + * b + * + * @example + * \`\`\`ts + * const x = 1 + * \`\`\` + */ +const v = 1` +) diff --git a/scripts/codemods/ts-fence.ts b/scripts/codemods/ts-fence.ts new file mode 100644 index 00000000000..2281f3ae0ed --- /dev/null +++ b/scripts/codemods/ts-fence.ts @@ -0,0 +1,35 @@ +import type cs from "jscodeshift" + +const EXAMPLE = "* @example\n" +const EXAMPLE_WITH_FENCE = "* @example\n * ```ts\n" + +export default function transformer(file: cs.FileInfo, api: cs.API) { + const j = api.jscodeshift + const root = j(file.source) + + root.find(j.Comment as any).forEach((path) => { + if (path.value.type === "CommentBlock") { + const value = (path.value) as any + const comment = value.value + if (comment.includes(EXAMPLE) && !comment.includes(EXAMPLE_WITH_FENCE)) { + value.value = wrapExamplesWithFence(comment) + } + } + }) + + return root.toSource() +} + +function wrapExamplesWithFence(jsdocComment: string) { + const start = jsdocComment.indexOf(EXAMPLE) + EXAMPLE.length + let end = jsdocComment.indexOf(" * @", start) + if (end === -1) { + end = jsdocComment.length - 1 + } else { + if (jsdocComment.substring(end - 3, end) === " *\n") { + end -= 3 + } + } + return jsdocComment.substring(0, start) + " * ```ts\n" + jsdocComment.substring(start, end) + " * ```\n" + + jsdocComment.substring(end) +} diff --git a/scripts/codemods/vitest.config.ts b/scripts/codemods/vitest.config.ts new file mode 100644 index 00000000000..0a565d350a7 --- /dev/null +++ b/scripts/codemods/vitest.config.ts @@ -0,0 +1,5 @@ +export default { + test: { + globals: true + } +} diff --git a/scripts/jsdocs/code2jsdoc-example.html b/scripts/jsdocs/code2jsdoc-example.html index 27cdbb98f4c..d9e381735d2 100644 --- a/scripts/jsdocs/code2jsdoc-example.html +++ b/scripts/jsdocs/code2jsdoc-example.html @@ -30,31 +30,9 @@

code 2 jsdoc @example

cols="80" rows="40" onkeyup="document.getElementById('comment').value = t(this.value)" - > -import { Effect } from "effect" - -// ┌─── Effect -// ▼ -const success = Effect.succeed(42) - - + > +