success
SourceCreates the successful branch of a Result.
Helpers
Minimal explicit success/failure values used across the public API.
Result is intentionally small in this library:
Use this when an operation can fail because of runtime data, but that failure should remain visible and typed instead of being hidden behind exceptions or implicit coercion.
In practical ECS code this is the shared language for construction-time validation and fallible lookups. It keeps ordinary failure in the type surface instead of pushing it into exceptions.
// Validate several authored inputs and keep every failure explicit.
const built = Result.all({
position: Vector2.result({ x: 4, y: 8 }),
size: Size2.result({ width: 16, height: 16 })
})
Small helpers that create explicit success or failure values.
Type guards that narrow one result to its successful or failed branch.
Pure helpers that fold or aggregate explicit result values.
Folds one Result into a plain value.
Use this when you are leaving the Result shape and want one explicit place to handle both branches.
const label = Result.match(Vector2.result({ x: 0, y: 0 }), {
onSuccess: () => "ok",
onFailure: () => "invalid"
})
Aggregates several independent results into one explicit result.
Tuple input preserves tuple ordering in both success and failure shapes. Record input preserves the original keys.
The first failure stays explicit in the returned error structure rather than throwing or silently dropping invalid entries.
const geometry = Result.all({
position: Vector2.result({ x: 10, y: 20 }),
size: Size2.result({ width: 32, height: 16 })
})