# implement() function

> The implement() function types call handlers against a schema's calls, for handlers kept in their own files.

The **`implement()`** function types call handlers against a schema's calls and returns them as given, so handlers kept in their own files can be spread into `defineRoom()`'s `calls`.

## Syntax

```ts
implement(schema, handlers)
```

### Parameters

`schema`
: The [`Schema`](/docs/room/schema) that declares the calls.

`handlers`
: An object with a handler for any of the schema's calls. Each takes the args first, then `{ room, connection }`, and returns or resolves to the reply.

### Return value

`handlers`, unchanged.

## Description

`implement()` does nothing at runtime; it's there for the types. `defineRoom()` still reports a declared call with no handler, so spreading several files' handlers, `calls: { ...shop, ...combat }`, checks that every call has one.

## Examples

### Handlers split across files

```ts
// schema.ts
import { call, defineCalls, defineSchema, entity } from "@irtio/room";

export const Hero = entity("hero", { hp: "u16", gold: "u32" });
export const schema = defineSchema({
  private: Hero,
  calls: defineCalls({ heal: call().returns<number>(), loot: call({ gold: "u16" }) }),
});
```

```ts
// healer.ts
import { implement } from "@irtio/room";
import { schema } from "./schema.js";

export const healer = implement(schema, {
  heal(_args, { room, connection }) {
    const hero = room.private(connection);
    hero.hp = Math.min(hero.hp + 25, 100);
    return hero.hp;
  },
});
```

```ts
// dungeon.ts
import { defineRoom } from "@irtio/room";
import { healer } from "./healer.js";
import { schema } from "./schema.js";

export default defineRoom({
  schema,
  calls: {
    ...healer,
    loot({ gold }, { room, connection }) {
      room.private(connection).gold += gold;
    },
  },
});
```

## See also

- [`defineCalls()`](/docs/room/definecalls)
- [Handlers in their own files](/docs/room/guides/calls#handlers-in-their-own-files)
