Skip to content

Commit d9f08d8

Browse files
committed
Update package dependencies and refactor Program.ts to implement user and pet schemas with matching functionality
1 parent b7e974b commit d9f08d8

3 files changed

Lines changed: 178 additions & 4 deletions

File tree

package-lock.json

Lines changed: 145 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"eslint-plugin-import": "^2.30.0",
5555
"eslint-plugin-simple-import-sort": "^12.1.1",
5656
"eslint-plugin-sort-destructure-keys": "^2.0.0",
57-
"tsx": "^4.17.0",
57+
"ts-node": "^10.9.2",
58+
"tsx": "^4.20.3",
5859
"typescript": "^5.6.2",
5960
"vitest": "^3.2.0"
6061
},
@@ -76,4 +77,4 @@
7677
"babel-plugin-annotate-pure-calls@0.4.0": "patches/babel-plugin-annotate-pure-calls@0.4.0.patch"
7778
}
7879
}
79-
}
80+
}

src/Program.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
import { Match, Schema } from "effect"
12
import * as Effect from "effect/Effect"
23

3-
Effect.runPromise(Effect.log("Hello, World!"))
4+
const User = Schema.TaggedStruct("User", {
5+
name: Schema.String,
6+
age: Schema.Number
7+
})
8+
type IUser = Schema.Schema.Type<typeof User>
9+
10+
const john = User.make({ name: "John", age: 44 })
11+
12+
const Pet = Schema.TaggedStruct("Pet", {
13+
name: Schema.String,
14+
age: Schema.Number
15+
})
16+
type IPet = Schema.Schema.Type<typeof Pet>
17+
18+
const dog = Pet.make({ name: "Dog", age: 5 })
19+
20+
type IEntities = IUser | IPet
21+
22+
const engine = Match.type<IEntities>().pipe(
23+
Match.tag("Pet", (input) => {
24+
console.log(`Pet: ${input.name}, Age: ${input.age}`)
25+
}),
26+
Match.tag("User", (input) => {
27+
console.log(`User: ${input.name}, Age: ${input.age}`)
28+
}),
29+
Match.exhaustive
30+
)
31+
32+
console.log(engine(dog))

0 commit comments

Comments
 (0)