Skip to content

Commit ec6cb5d

Browse files
authored
Add the missing TypeScript fences to the recent examples. (#4066)
1 parent 5a701a3 commit ec6cb5d

File tree

5 files changed

+88
-16
lines changed

5 files changed

+88
-16
lines changed

packages/effect/src/BigDecimal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,13 @@ export const fromNumber: (n: number) => BigDecimal = unsafeFromNumber
895895
* @param n - The `number` value to create a `BigDecimal` from.
896896
*
897897
* @example
898+
* ```ts
898899
* import { BigDecimal, Option } from "effect"
899900
*
900901
* assert.deepStrictEqual(BigDecimal.safeFromNumber(123), Option.some(BigDecimal.make(123n, 0)))
901902
* assert.deepStrictEqual(BigDecimal.safeFromNumber(123.456), Option.some(BigDecimal.make(123456n, 3)))
902903
* assert.deepStrictEqual(BigDecimal.safeFromNumber(Infinity), Option.none())
904+
* ```
903905
*
904906
* @since 3.11.0
905907
* @category constructors
@@ -1058,9 +1060,11 @@ export const format = (n: BigDecimal): string => {
10581060
* @param n - The `BigDecimal` to format.
10591061
*
10601062
* @example
1063+
* ```ts
10611064
* import { toExponential, make } from "effect/BigDecimal"
10621065
*
10631066
* assert.deepStrictEqual(toExponential(make(123456n, -5)), "1.23456e+10")
1067+
* ```
10641068
*
10651069
* @since 3.11.0
10661070
* @category conversions

packages/effect/src/Context.ts

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,55 @@ export const omit: <Services, S extends Array<ValidTagsById<Services>>>(
485485
export const Tag: <const Id extends string>(id: Id) => <Self, Shape>() => TagClass<Self, Id, Shape> = internal.Tag
486486

487487
/**
488+
* Creates a context tag with a default value.
489+
*
490+
* **Details**
491+
*
492+
* `Context.Reference` allows you to create a tag that can hold a value. You can
493+
* provide a default value for the service, which will automatically be used
494+
* when the context is accessed, or override it with a custom implementation
495+
* when needed.
496+
*
488497
* @example
489-
* import { Context, Layer } from "effect"
498+
* ```ts
499+
* // Title: Declaring a Tag with a default value
500+
* import { Context, Effect } from "effect"
501+
*
502+
* class SpecialNumber extends Context.Reference<SpecialNumber>()(
503+
* "SpecialNumber",
504+
* { defaultValue: () => 2048 }
505+
* ) {}
506+
*
507+
* // ┌─── Effect<void, never, never>
508+
* // ▼
509+
* const program = Effect.gen(function* () {
510+
* const specialNumber = yield* SpecialNumber
511+
* console.log(`The special number is ${specialNumber}`)
512+
* })
513+
*
514+
* // No need to provide the SpecialNumber implementation
515+
* Effect.runPromise(program)
516+
* // Output: The special number is 2048
517+
* ```
490518
*
491-
* class MyTag extends Context.Reference<MyTag>()("MyTag", {
492-
* defaultValue: () => ({ myNum: 108 })
493-
* }) {
494-
* static Live = Layer.succeed(this, { myNum: 108 })
495-
* }
519+
* @example
520+
* ```ts
521+
* // Title: Overriding the default value
522+
* import { Context, Effect } from "effect"
523+
*
524+
* class SpecialNumber extends Context.Reference<SpecialNumber>()(
525+
* "SpecialNumber",
526+
* { defaultValue: () => 2048 }
527+
* ) {}
528+
*
529+
* const program = Effect.gen(function* () {
530+
* const specialNumber = yield* SpecialNumber
531+
* console.log(`The special number is ${specialNumber}`)
532+
* })
533+
*
534+
* Effect.runPromise(program.pipe(Effect.provideService(SpecialNumber, -1)))
535+
* // Output: The special number is -1
536+
* ```
496537
*
497538
* @since 3.11.0
498539
* @category constructors

packages/effect/src/Effect.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10033,27 +10033,47 @@ export namespace fn {
1003310033
*
1003410034
* The function can be created both using a generator function that can yield effects or using a normal function.
1003510035
*
10036-
* @since 3.11.0
10037-
* @category function
10036+
* `Effect.fn` also acts as a `pipe` function, allowing you to create a pipeline after the function definition.
1003810037
*
1003910038
* @example
10039+
* ```ts
10040+
* // Title: Creating a traced function with a generator function
1004010041
* import { Effect } from "effect"
1004110042
*
1004210043
* const logExample = Effect.fn("logExample")(
1004310044
* function*<N extends number>(n: N) {
1004410045
* yield* Effect.annotateCurrentSpan("n", n)
1004510046
* yield* Effect.logInfo(`got: ${n}`)
1004610047
* yield* Effect.fail(new Error())
10047-
* },
10048-
* Effect.delay("1 second")
10048+
* }
1004910049
* )
1005010050
*
1005110051
* Effect.runFork(
10052-
* // this location is printed on the stack trace of the following `Effect.logError`
10052+
* // This location is printed in the stack trace of the following `Effect.logError`
1005310053
* logExample(100).pipe(
1005410054
* Effect.catchAllCause(Effect.logError)
1005510055
* )
1005610056
* )
10057+
* ```
10058+
*
10059+
* @example
10060+
* ```ts
10061+
* // Title: Creating a traced function with a pipeline
10062+
* import { Effect } from "effect"
10063+
*
10064+
* const logExample = Effect.fn("example")(
10065+
* function* <N extends number>(n: N) {
10066+
* yield* Effect.annotateCurrentSpan("n", n)
10067+
* yield* Effect.logInfo(`got: ${n}`)
10068+
* yield* Effect.fail(new Error())
10069+
* },
10070+
* // Add a delay to the effect
10071+
* Effect.delay("1 second")
10072+
* )
10073+
* ```
10074+
*
10075+
* @since 3.11.0
10076+
* @category function
1005710077
*/
1005810078
export const fn: (
1005910079
name: string,

packages/effect/src/Micro.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,13 +3853,14 @@ export const whileLoop: <A, E, R>(options: {
38533853
})
38543854

38553855
/**
3856-
* For each element of the provided iterable, run the effect and collect the results.
3856+
* For each element of the provided iterable, run the effect and collect the
3857+
* results.
38573858
*
38583859
* If the `discard` option is set to `true`, the results will be discarded and
38593860
* the effect will return `void`.
38603861
*
3861-
* The `concurrency` option can be set to control how many effects are run in
3862-
* parallel. By default, the effects are run sequentially.
3862+
* The `concurrency` option can be set to control how many effects are run
3863+
* concurrently. By default, the effects are run sequentially.
38633864
*
38643865
* @since 3.4.0
38653866
* @experimental
@@ -3971,7 +3972,8 @@ export const forEach: {
39713972
/**
39723973
* Effectfully filter the elements of the provided iterable.
39733974
*
3974-
* Use the `concurrency` option to control how many elements are processed in parallel.
3975+
* Use the `concurrency` option to control how many elements are processed
3976+
* concurrently.
39753977
*
39763978
* @since 3.4.0
39773979
* @experimental
@@ -3990,7 +3992,8 @@ export const filter = <A, E, R>(iterable: Iterable<A>, f: (a: NoInfer<A>) => Mic
39903992
/**
39913993
* Effectfully filter the elements of the provided iterable.
39923994
*
3993-
* Use the `concurrency` option to control how many elements are processed in parallel.
3995+
* Use the `concurrency` option to control how many elements are processed
3996+
* concurrently.
39943997
*
39953998
* @since 3.4.0
39963999
* @experimental

packages/platform/src/UrlParams.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ const baseUrl = (): string | undefined => {
216216
* (when more than one value for a key)
217217
*
218218
* @example
219+
* ```ts
219220
* import { UrlParams } from "@effect/platform"
220221
*
221222
* const urlParams = UrlParams.fromInput({ a: 1, b: true, c: "string", e: [1, 2, 3] })
@@ -225,6 +226,7 @@ const baseUrl = (): string | undefined => {
225226
* result,
226227
* { "a": "1", "b": "true", "c": "string", "e": ["1", "2", "3"] }
227228
* )
229+
* ```
228230
*
229231
* @since 1.0.0
230232
* @category conversions
@@ -268,6 +270,7 @@ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: Pa
268270
* Extract schema from all key-value pairs in the given `UrlParams`.
269271
*
270272
* @example
273+
* ```ts
271274
* import { Effect, Schema } from "effect"
272275
* import { UrlParams } from "@effect/platform"
273276
*
@@ -283,6 +286,7 @@ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: Pa
283286
* b: false
284287
* })
285288
* })
289+
* ```
286290
*
287291
* @since 1.0.0
288292
* @category schema

0 commit comments

Comments
 (0)