# factory

```erlang
flatten :: Object specification => (Any, Any, ...) -> Object
```

## description

Create a factory function using the provided specification object. The `factory` method has 2 magical powers:

* the specification object can contain constant values, but also functions which will be called everytime the factory function is called (arguments will be passed as-is)
* the specification object can be nested: `factory` works recursively.

## examples

### constant values

```javascript
import { factory } from 'conductor'

const spec = { name: 'Elliot', type: 'hacker' }
const Hacker = factory(spec)
Hacker() // { name: 'Elliot', type: 'hacker' }
```

### function values

```javascript
import { factory } from 'conductor'

const spec = { name: x => x, createdAt: () => Date.now() }
const Hacker = factory(spec)
Hacker('Elliot') // { name: 'Elliot', createdAt: 1529249582304 }
```

### nested specification

```javascript
import { factory } from 'conductor'

const spec = {
  id: 1,
  name: x => x,
  metadata: {
    createdAt: () => Date.now(),
    type: 'hacker'
  }
const Hacker = factory(spec)
Hacker('Elliot')
// {
//   id: 1,
//   name: 'Elliot',
//   metadata: {
//     createdAt: 1529249582304,
//     type: 'hacker'
//   }
// }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://conductor.js.org/api-reference/factory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
