Skip to content

Commit eb3657d

Browse files
committed
update readme
1 parent 6bd755d commit eb3657d

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,39 @@ oc.init <- function() {
5959
```
6060

6161
```typescript
62-
// ocap.ts
63-
import { numeric, list, ocap } from "rserve-ts/types";
62+
// app.ts
63+
import { z } from "zod";
64+
import { Robj } from "../index";
6465

65-
export const appFuns = {
66-
add: ocap([z.number(), z.number()], numeric()),
67-
dist: ocap(
66+
export const appSchema = {
67+
add: Robj.ocap([z.number(), z.number()], Robj.numeric(1)),
68+
dist: Robj.ocap(
6869
[z.enum(["normal", "uniform"])],
69-
list({
70-
sample: ocap([z.number()], numeric()),
70+
Robj.list({
71+
sample: Robj.ocap([z.number()], Robj.numeric()),
7172
})
7273
),
7374
};
7475
```
7576

7677
```typescript
77-
import { RserveClient } from "rserve-ts";
78-
import { appFuns } from "./ocap";
78+
// app.ts
79+
import R from "../index";
80+
import { appSchema } from "./app";
7981

8082
(async () => {
81-
const R = await RserveClient.create({
82-
host: "http://127.0.0.1:8081",
83-
});
84-
85-
const app = await R.ocap(appFuns);
86-
87-
const sum = await app.add(1, 2);
88-
console.log("1 + 2 = ", sum);
89-
90-
const chosenDist = await app.dist("normal");
91-
const sample = await chosenDist.sample(5);
92-
console.log("Normal sample: ", sample);
83+
const s = await R.create({ host: "ws://localhost:8181" });
84+
const app = await s.ocap(appSchema);
85+
86+
const sum = await app.add(16, 32);
87+
const cart = { total: sum };
88+
cart.total;
89+
90+
const { sample } = await app.dist("uniform");
91+
const x = await sample(235);
92+
if (typeof x === "number") x + 5;
93+
else {
94+
// deal with an array
95+
}
9396
})();
9497
```

0 commit comments

Comments
 (0)