Skip to content

Commit 70f9c35

Browse files
committed
feat: pretty type extractions
1 parent 18fbd6a commit 70f9c35

30 files changed

Lines changed: 159 additions & 317 deletions

content/src/content/docs/docs/ai/getting-started.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ This allows Effect to track which services should be added to the requirements o
166166

167167
### Creating an `AiModel`
168168

169-
To create an `AiModel`, you can use the model-specific factory from one of Effect's provider integration packages.
169+
To create an `AiModel`, you can use the model-specific factory from one of Effect's provider integration packages.
170170

171171
**Example** (Defining an `AiModel` to Interact with OpenAi)
172172

@@ -185,7 +185,7 @@ This creates an `AiModel` that:
185185

186186
### Providing an `AiModel`
187187

188-
Once you've created an `AiModel`, you can directly `Effect.provide` it to your Effect programs just like any other service:
188+
Once you've created an `AiModel`, you can directly `Effect.provide` it to your Effect programs just like any other service:
189189

190190
```ts
191191
import { OpenAiLanguageModel } from "@effect/ai-openai"
@@ -238,7 +238,7 @@ const main = Effect.gen(function*() {
238238

239239
**Flexibility**
240240

241-
If we know that one model or provider performs better at a given task than another, we can freely mix and match models and providers together.
241+
If we know that one model or provider performs better at a given task than another, we can freely mix and match models and providers together.
242242

243243
For example, if we know Anthropic's Claude generates some really great dad jokes, we can mix it into our existing program with just a few lines of code:
244244

@@ -292,7 +292,7 @@ const Claude37 = AnthropicLanguageModel.model("claude-3-7-sonnet-latest")
292292
class DadJokes extends Effect.Service<DadJokes>()("app/DadJokes", {
293293
effect: Effect.gen(function*() {
294294
// Yielding the model will return a layer with no requirements
295-
//
295+
//
296296
// ┌─── Layer<AiLanguageModel>
297297
//
298298
const gpt = yield* Gpt4o
@@ -313,7 +313,7 @@ class DadJokes extends Effect.Service<DadJokes>()("app/DadJokes", {
313313
})
314314
}) {}
315315

316-
// Programs which utilize the `DadJokes` service have no knowledge of
316+
// Programs which utilize the `DadJokes` service have no knowledge of
317317
// any AI requirements
318318
//
319319
// ┌─── Effect<void, AiError, DadJokes>
@@ -333,7 +333,7 @@ DadJokes.Default
333333

334334
## Create a Provider Client
335335

336-
To make our code executable, we must finish satisfying our program's requirements.
336+
To make our code executable, we must finish satisfying our program's requirements.
337337

338338
Let's take another look at our program from earlier:
339339

@@ -359,7 +359,7 @@ const main = generateDadJoke.pipe(
359359
)
360360
```
361361

362-
We can see that our `main` program still requires us to provide an `OpenAiClient`.
362+
We can see that our `main` program still requires us to provide an `OpenAiClient`.
363363

364364
Each of our provider integration packages exports a client module that can be used to construct a client for that provider.
365365

@@ -400,7 +400,7 @@ The provider clients also have a dependency on an `HttpClient` implementation to
400400

401401
For example, if we know we are going to run this code in NodeJS, we can utilize the `NodeHttpClient` module from `@effect/platform-node` to provide an `HttpClient` implementation:
402402

403-
```ts twoslash /{ (NodeHttpClient) }|, (HttpClient)>|, (never)>/ {35} collapse={6-18}
403+
```ts twoslash /{ (NodeHttpClient) }|, (HttpClient)>|, (never)>/ {35} collapse={6-18}
404404
import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai"
405405
import { AiLanguageModel } from "@effect/ai"
406406
import { NodeHttpClient } from "@effect/platform-node"
@@ -429,7 +429,7 @@ const OpenAi = OpenAiClient.layerConfig({
429429
apiKey: Config.redacted("OPENAI_API_KEY")
430430
})
431431

432-
// Provide a platform-specific implementation of `HttpClient` to our
432+
// Provide a platform-specific implementation of `HttpClient` to our
433433
// OpenAi layer
434434
//
435435
// ┌─── Layer<OpenAiClient, ConfigError, never>
@@ -439,7 +439,7 @@ const OpenAiWithHttp = Layer.provide(OpenAi, NodeHttpClient.layerUndici)
439439

440440
## Running the Program
441441

442-
Now that we have a `Layer` which provides us with an `OpenAiClient`, we're ready to make our `main` program runnable.
442+
Now that we have a `Layer` which provides us with an `OpenAiClient`, we're ready to make our `main` program runnable.
443443

444444
Our final program looks like the following:
445445

content/src/content/docs/docs/behaviour/order.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ interface Person {
9797
}
9898

9999
// Create a custom order to sort Person objects by name in ascending order
100-
//
101-
// ┌─── Order<Person>
102-
//
103100
const byName = Order.mapInput(
101+
// ^?
104102
Order.string,
105103
(person: Person) => person.name
106104
)

content/src/content/docs/docs/code-style/pattern-matching.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import { Match } from "effect"
2121
// Simulated dynamic input that can be a string or a number
2222
const input: string | number = "some input"
2323

24-
// ┌─── string
25-
//
2624
const result = Match.value(input).pipe(
25+
// ^?
2726
// Match if the value is a number
2827
Match.when(Match.number, (n) => `number: ${n}`),
2928
// Match if the value is a string
@@ -66,10 +65,8 @@ The `Match.type` constructor defines a `Matcher` that operates on a specific typ
6665
import { Match } from "effect"
6766

6867
// Create a matcher for values that are either strings or numbers
69-
//
70-
// ┌─── (u: string | number) => string
71-
//
7268
const match = Match.type<string | number>().pipe(
69+
// ^?
7370
// Match when the value is a number
7471
Match.when(Match.number, (n) => `number: ${n}`),
7572
// Match when the value is a string

content/src/content/docs/docs/concurrency/deferred.mdx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ A deferred can be created using the `Deferred.make` constructor. This returns an
3333
```ts twoslash
3434
import { Deferred } from "effect"
3535

36-
// ┌─── Effect<Deferred<string, Error>>
37-
//
3836
const deferred = Deferred.make<string, Error>()
37+
// ^?
3938
```
4039

4140
## Awaiting
@@ -45,13 +44,11 @@ To retrieve a value from a deferred, you can use `Deferred.await`. This operatio
4544
```ts twoslash
4645
import { Effect, Deferred } from "effect"
4746

48-
// ┌─── Effect<Deferred<string, Error>, never, never>
49-
//
5047
const deferred = Deferred.make<string, Error>()
48+
// ^?
5149

52-
// ┌─── Effect<string, Error, never>
53-
//
5450
const value = deferred.pipe(Effect.andThen(Deferred.await))
51+
// ^?
5552
```
5653

5754
## Completing

content/src/content/docs/docs/concurrency/fibers.mdx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ const fib = (n: number): Effect.Effect<number> =>
7171
? Effect.succeed(n)
7272
: Effect.zipWith(fib(n - 1), fib(n - 2), (a, b) => a + b)
7373

74-
// ┌─── Effect<RuntimeFiber<number, never>, never, never>
75-
//
7674
const fib10Fiber = Effect.fork(fib(10))
75+
// ^?
7776
```
7877

7978
## Joining Fibers
@@ -90,9 +89,8 @@ const fib = (n: number): Effect.Effect<number> =>
9089
? Effect.succeed(n)
9190
: Effect.zipWith(fib(n - 1), fib(n - 2), (a, b) => a + b)
9291

93-
// ┌─── Effect<RuntimeFiber<number, never>, never, never>
94-
//
9592
const fib10Fiber = Effect.fork(fib(10))
93+
// ^?
9694

9795
const program = Effect.gen(function* () {
9896
// Retrieve the fiber
@@ -119,9 +117,8 @@ const fib = (n: number): Effect.Effect<number> =>
119117
? Effect.succeed(n)
120118
: Effect.zipWith(fib(n - 1), fib(n - 2), (a, b) => a + b)
121119

122-
// ┌─── Effect<RuntimeFiber<number, never>, never, never>
123-
//
124120
const fib10Fiber = Effect.fork(fib(10))
121+
// ^?
125122

126123
const program = Effect.gen(function* () {
127124
// Retrieve the fiber
@@ -483,9 +480,8 @@ const child = Effect.repeat(
483480
Schedule.fixed("1 second")
484481
)
485482

486-
// ┌─── Effect<void, never, Scope>
487-
//
488483
const parent = Effect.gen(function* () {
484+
// ^?
489485
console.log("parent: started!")
490486
// Child fiber attached to local scope
491487
yield* Effect.forkScoped(child)

content/src/content/docs/docs/configuration.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ When you log a `Redacted` value using `console.log`, the actual content remains
159159
import { Effect, Config, Redacted } from "effect"
160160

161161
const program = Effect.gen(function* () {
162-
// ┌─── Redacted<string>
163-
//
164162
const redacted = yield* Config.redacted("API_KEY")
163+
// ^?
165164

166165
// Log the redacted value, which won't reveal the actual secret
167166
console.log(`Console output: ${redacted}`)
@@ -199,10 +198,8 @@ import { Effect, Config, Redacted } from "effect"
199198

200199
const program = Effect.gen(function* () {
201200
// Wrap the validated number configuration with redaction
202-
//
203-
// ┌─── Redacted<number>
204-
//
205201
const redacted = yield* Config.redacted(Config.number("SECRET"))
202+
// ^?
206203

207204
console.log(`Console output: ${redacted}`)
208205
console.log(`Actual value: ${Redacted.value(redacted)}`)

content/src/content/docs/docs/data-types/cause.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ You can intentionally create an effect with a specific cause using `Effect.failC
2727
import { Effect, Cause } from "effect"
2828

2929
// Define an effect that dies with an unexpected error
30-
//
31-
// ┌─── Effect<never, never, never>
32-
//
3330
const die = Effect.failCause(Cause.die("Boom!"))
31+
// ^?
3432

3533
// Define an effect that fails with an expected error
36-
//
37-
// ┌─── Effect<never, string, never>
38-
//
3934
const fail = Effect.failCause(Cause.fail("Oh no!"))
35+
// ^?
4036
```
4137

4238
Some causes do not influence the error type of the effect, leading to `never` in the error channel:

content/src/content/docs/docs/data-types/chunk.mdx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ Create an empty `Chunk` with `Chunk.empty`.
3333
```ts twoslash
3434
import { Chunk } from "effect"
3535

36-
// ┌─── Chunk<number>
37-
//
3836
const chunk = Chunk.empty<number>()
37+
// ^?
3938
```
4039

4140
### make
@@ -47,9 +46,8 @@ To create a `Chunk` with specific values, use `Chunk.make(...values)`. Note that
4746
```ts twoslash
4847
import { Chunk } from "effect"
4948

50-
// ┌─── NonEmptyChunk<number>
51-
//
5249
const chunk = Chunk.make(1, 2, 3)
50+
// ^?
5351
```
5452

5553
### fromIterable
@@ -100,10 +98,8 @@ To combine two `Chunk` instances into one, use `Chunk.appendAll`.
10098
import { Chunk } from "effect"
10199

102100
// Concatenate two chunks with different types of elements
103-
//
104-
// ┌─── NonEmptyChunk<string | number>
105-
//
106101
const chunk = Chunk.appendAll(Chunk.make(1, 2), Chunk.make("a", "b"))
102+
// ^?
107103

108104
console.log(chunk)
109105
/*
@@ -156,17 +152,14 @@ Convert a `Chunk` to a `ReadonlyArray` using `Chunk.toReadonlyArray`. The result
156152
```ts twoslash
157153
import { Chunk } from "effect"
158154

159-
// ┌─── readonly [number, ...number[]]
160-
//
161155
const nonEmptyArray = Chunk.toReadonlyArray(Chunk.make(1, 2, 3))
156+
// ^?
162157

163-
// ┌─── readonly never[]
164-
//
165158
const emptyArray = Chunk.toReadonlyArray(Chunk.empty())
159+
// ^?
166160

167161
declare const chunk: Chunk.Chunk<number>
168162

169-
// ┌─── readonly number[]
170-
//
171163
const array = Chunk.toReadonlyArray(chunk)
164+
// ^?
172165
```

content/src/content/docs/docs/data-types/data.mdx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ However, the `Data.struct` constructor allows you to compare values based on the
3636
```ts twoslash
3737
import { Data, Equal } from "effect"
3838

39-
// ┌─── { readonly name: string; readonly age: number; }
40-
//
4139
const alice = Data.struct({ name: "Alice", age: 30 })
40+
// ^?
4241

4342
// Check if Alice is equal to a new object
4443
// with the same structure and values
@@ -104,9 +103,8 @@ To represent your data using tuples, you can use the `Data.tuple` constructor. T
104103
```ts twoslash
105104
import { Data, Equal } from "effect"
106105

107-
// ┌─── readonly [string, number]
108-
//
109106
const alice = Data.tuple("Alice", 30)
107+
// ^?
110108

111109
// Check if Alice is equal to a new tuple
112110
// with the same structure and values
@@ -133,9 +131,8 @@ You can use `Data.array` to create an array-like data structure that supports st
133131
```ts twoslash
134132
import { Data, Equal } from "effect"
135133

136-
// ┌─── readonly number[]
137-
//
138134
const numbers = Data.array([1, 2, 3, 4, 5])
135+
// ^?
139136

140137
// Check if the array is equal to a new array
141138
// with the same values
@@ -179,10 +176,8 @@ interface Person {
179176
}
180177

181178
// Create a constructor for `Person`
182-
//
183-
// ┌─── (args: { readonly name: string; }) => Person
184-
//
185179
const make = Data.case<Person>()
180+
// ^?
186181

187182
const alice = make({ name: "Alice" })
188183

0 commit comments

Comments
 (0)