Skip to content

Commit 950e1da

Browse files
committed
refactor(go): use Go generics for union types
Address review feedback from chaokunyang. Since Go 1.23+ is used, replace interface{}-based Union with generic Union2, Union3, Union4 types. New API: - Union2[T1, T2], Union3[T1, T2, T3], Union4[T1, T2, T3, T4] generic types - NewUnion2A/B, NewUnion3A/B/C, NewUnion4A/B/C/D constructors - Match() methods for pattern matching (type-safe callbacks) - Index(), IsFirst(), IsSecond() accessor methods - First(), Second() value extraction methods (panics on wrong access) - RegisterUnion2Type, RegisterUnion3Type, RegisterUnion4Type functions Benefits: - Compile-time type safety - Explicit variant tracking - Pattern matching support - No runtime type assertions needed
1 parent b5c0657 commit 950e1da

File tree

2 files changed

+551
-237
lines changed

2 files changed

+551
-237
lines changed

0 commit comments

Comments
 (0)