Skip to content

Creation Patterns

Pony constructors always return an initialized instance of their type. There’s no null, no uninitialized state, and actor constructors can’t be partial. These constraints push you toward patterns that might be unfamiliar if you’re coming from languages where constructors can fail freely or return null.

FFI Global Initializer uses a primitive’s _init method to run C library initialization exactly once, taking advantage of the fact that primitives are singletons.

Static Constructor wraps object construction in a primitive’s apply method so it can return either the constructed object or a meaningful error, something Pony constructors can’t do on their own.

Supply Chain solves the problem of actor constructors that depend on things that can fail. Rather than juggling (File | None) unions inside the actor, you initialize dependencies before constructing the actor and pass them in fully built.

Typed Step Builder enforces construction order at compile time. Each build step returns a different interface type, so the compiler prevents calling steps out of order or skipping required fields.