Problem
The result/builder.ts file mixes internal classes (Ok, Err) with standalone utility functions (map, flatMap, isOk, etc.). This violates the project's file-organization rule which states "Types and functions must not be mixed in the same file."
Why It Matters
- Harder to navigate - related code is mixed together
- Violates project conventions for file structure
- Makes it harder to maintain and test each concern separately
- Blurs the line between internal implementation and public API
Current vs Expected DX
// Current - mixed in single file
result/builder.ts // Contains both classes AND functions
// Expected - separated by concern
result/classes.ts // Ok and Err internal classes
result/functions.ts // Standalone utility functions
result/index.ts // Re-exports only
Current Situation
Currently result/builder.ts contains:
- Internal
Ok and Err classes (lines 15-73)
- Factory functions
ok(), err() (lines 82, 90)
- Standalone functions
isOk(), isErr(), map(), flatMap(), etc.
This violates the file organization rule.
What Would Change
Split result/builder.ts into:
-
result/classes.ts - Internal Ok/Err classes
class Ok<T, E>
class Err<E>
-
result/functions.ts - All standalone functions
- Factory functions:
ok(), err()
- Type guards:
isOk(), isErr()
- Operations:
map(), flatMap(), mapErr(), tap(), tapErr(), etc.
- Combinators:
all(), traverse(), swap(), etc.
- Conversions:
toNullable(), toUndefined(), unwrap()
-
result/index.ts - Re-exports only (already exists)
Code Example
Current structure:
result/
├── index.ts // Re-exports
├── types.ts // Type definitions only
├── builder.ts // MIXED: classes + functions together
└── ...
Expected structure:
result/
├── index.ts // Re-exports
├── types.ts // Type definitions only
├── classes.ts // Internal Ok/Err classes
├── functions.ts // All standalone functions
└── ...
Implementation Notes
- Both
classes.ts and functions.ts should export the same public API
- Internal classes in
classes.ts should not be exported from index.ts
- Factory functions
ok() and err() should be in functions.ts and use classes from classes.ts
- No changes to the public API - only internal file reorganization
Co-Authored-By: martyy-code nesalia.inc@gmail.com
Problem
The
result/builder.tsfile mixes internal classes (Ok,Err) with standalone utility functions (map,flatMap,isOk, etc.). This violates the project's file-organization rule which states "Types and functions must not be mixed in the same file."Why It Matters
Current vs Expected DX
Current Situation
Currently
result/builder.tscontains:OkandErrclasses (lines 15-73)ok(),err()(lines 82, 90)isOk(),isErr(),map(),flatMap(), etc.This violates the file organization rule.
What Would Change
Split
result/builder.tsinto:result/classes.ts- Internal Ok/Err classesclass Ok<T, E>class Err<E>result/functions.ts- All standalone functionsok(),err()isOk(),isErr()map(),flatMap(),mapErr(),tap(),tapErr(), etc.all(),traverse(),swap(), etc.toNullable(),toUndefined(),unwrap()result/index.ts- Re-exports only (already exists)Code Example
Current structure:
Expected structure:
Implementation Notes
classes.tsandfunctions.tsshould export the same public APIclasses.tsshould not be exported fromindex.tsok()anderr()should be infunctions.tsand use classes fromclasses.tsCo-Authored-By: martyy-code nesalia.inc@gmail.com