@@ -46,14 +46,15 @@ All modules implement identical functionality:
4646- ** isEmail** : Email validation using regex patterns
4747- ** formatCurrency** : Localized currency formatting
4848- ** clamp** : Constrain a number within an inclusive [ min, max] range
49+ - ** throttle** : Limit function execution to at most once per wait period
4950
5051## API Parity Contract
5152
5253This section defines the formal contract for cross-platform API consistency in KompKit.
5354
5455### What is Guaranteed
5556
56- - ** Function names** are identical across all platforms (` debounce ` , ` isEmail ` , ` formatCurrency ` , ` clamp ` ).
57+ - ** Function names** are identical across all platforms (` debounce ` , ` isEmail ` , ` formatCurrency ` , ` clamp ` , ` throttle ` ).
5758- ** Behavioral semantics** are identical: given the same inputs, all platforms produce the same observable output.
5859- ** Default values** are identical: ` wait = 250ms ` , ` currency = "USD" ` , ` locale = "en-US" ` .
5960- ** Error handling philosophy** is consistent: invalid inputs that cannot produce a meaningful result throw/throw-equivalent errors. Silent fallbacks are not permitted.
@@ -75,6 +76,7 @@ debounce(action, options) → Debounced<T> (with .cancel())
7576isEmail(value) → Boolean
7677formatCurrency(amount, options) → String
7778clamp(value, min, max) → Number
79+ throttle(fn, wait) → Throttled<T> (with .cancel())
7880```
7981
8082A developer familiar with the TypeScript API should be able to use the Kotlin or Dart API with only idiomatic adjustments — not conceptual re-learning.
@@ -127,6 +129,16 @@ export function formatCurrency(
127129): string ;
128130
129131export function clamp(value : number , min : number , max : number ): number ;
132+
133+ export interface Throttled <T extends (... args : any []) => void > {
134+ (... args : Parameters <T >): void ;
135+ cancel(): void ;
136+ }
137+
138+ export function throttle<T extends (... args : any []) => void >(
139+ fn : T ,
140+ wait : number , // must be > 0
141+ ): Throttled <T >;
130142```
131143
132144** Kotlin:**
@@ -152,6 +164,17 @@ fun formatCurrency(
152164): String
153165
154166fun clamp (value : Double , min : Double , max : Double ): Double
167+
168+ class Throttled <T >(private val invoke : (T ) -> Unit ) {
169+ operator fun invoke (value : T ): Unit
170+ fun cancel (): Unit
171+ }
172+
173+ fun <T > throttle (
174+ waitMs : Long , // must be > 0
175+ scope : CoroutineScope , // platform constraint: structured concurrency
176+ action : (T ) -> Unit ,
177+ ): Throttled <T >
155178```
156179
157180** Dart:**
@@ -176,6 +199,16 @@ String formatCurrency(
176199});
177200
178201double clamp(double value, double min, double max);
202+
203+ class Throttled<T> {
204+ void call(T arg);
205+ void cancel();
206+ }
207+
208+ Throttled<T> throttle<T>(
209+ void Function(T) fn,
210+ Duration wait, // must be > Duration.zero
211+ );
179212```
180213
181214### Platform-Specific Adaptations
@@ -189,6 +222,7 @@ While maintaining API consistency, we leverage platform strengths:
189222- ** Intl.NumberFormat** for currency formatting
190223- ** RegExp** for email validation
191224- ** Math.min/Math.max** for clamp
225+ - ** setTimeout/clearTimeout** for throttle timer
192226
193227#### Kotlin Implementation
194228
@@ -197,6 +231,7 @@ While maintaining API consistency, we leverage platform strengths:
197231- ** NumberFormat/Currency** for localized formatting
198232- ** Regex** for email validation
199233- ** Double.coerceIn** for clamp
234+ - ** Coroutine delay + Job** for throttle wait period
200235
201236#### Dart/Flutter Implementation
202237
@@ -205,6 +240,7 @@ While maintaining API consistency, we leverage platform strengths:
205240- ** RegExp** for email validation
206241- ** Null safety** with full type-safe APIs
207242- ** num.clamp** for clamp
243+ - ** Timer** for throttle scheduling (same as debounce)
208244
209245## Build System Architecture
210246
@@ -284,17 +320,19 @@ android.yml:
284320` ` `
285321packages/core/web/tests/
286322├── core.test.ts # debounce, isEmail, formatCurrency tests
287- └── clamp.test.ts # clamp unit tests
323+ ├── clamp.test.ts # clamp unit tests
324+ └── throttle.test.ts # throttle unit tests
288325
289326packages/core/android/src/test/kotlin/com/kompkit/core/
290- └── CoreTests.kt # All utility tests (incl. ClampTests)
327+ └── CoreTests.kt # All utility tests (incl. ThrottleTests, ClampTests)
291328
292329packages/core/flutter/test/
293330├── kompkit_core_test.dart # Integration tests
294331├── debounce_test.dart # Debounce unit tests
295332├── validate_test.dart # Validation unit tests
296333├── format_test.dart # Formatting unit tests
297- └── clamp_test.dart # Clamp unit tests
334+ ├── clamp_test.dart # Clamp unit tests
335+ └── throttle_test.dart # Throttle unit tests
298336```
299337
300338### Test Coverage
0 commit comments