Skip to main content

caxapok 0.1.0 copy "caxapok: ^0.1.0" to clipboard
caxapok: ^0.1.0 copied to clipboard

Syntactic sugar for Dart. Extensions for List, Iterable, Duration and Future, plus Kotlin-style scope functions.

[caxapok: a sugar cube on a retro refined-sugar pack]

CI [caxap ok]

Syntactic sugar for Dart: small, tested extensions for everyday code.

Install #

dart pub add caxapok
import 'package:caxapok/caxapok.dart';

Features #

Extension Members
List tryGet, nextAfter, maybeNextAfter, nearestAt, resizedDiscrete, splice
Iterable separated, firstIndexedWhereOrNull, lastIndexedWhereOrNull, difference, indexedDifference
Duration DurationExtension.max, DurationExtension.min, clamp, isZero, isNotZero, /
Future cancellable → CancellableTask, minDuration
Future<T> Function() retry
Any value let, also (Kotlin scope functions), repeat

Usage #

// List
[1, 2, 3].tryGet(10); // null
[1, 2, 3].nextAfter(3); // 1
[1, 2, null, null, 5].nearestAt(3); // 5
[1, 2, 3, 4, 5].splice(start: 1, count: 2); // [2, 3]

// Iterable
[1, 2, 3].separated(0); // (1, 0, 2, 0, 3)
final diff = [1, 3, 4].difference([1, 2, 4]);
diff.added; // [3]
diff.removed; // [2]

// Duration
const Duration(seconds: 30).clamp(Duration.zero, const Duration(seconds: 10)); // 0:00:10.000000

// Future
final task = Future.delayed(const Duration(seconds: 5), () => 'done').cancellable(
  onCancel: () => print('cleanup'),
);
await task.cancel(); // awaiting task now throws TaskCancelledException

await api.fetch().minDuration(const Duration(milliseconds: 300)); // no loader flicker
await api.fetch.retry(period: const Duration(seconds: 1), timeout: const Duration(seconds: 10));

// Any value
12.let((it) => it * 2); // 24
'a'.repeat(3); // [a, a, a]

cancel() discards the result but does not stop the original future. Stop the underlying work in onCancel.

See example/ for more.

Development #

Run all CI checks locally: ./scripts/run_ci_locally.sh. See LOCAL_CI_TESTING.md.


[caxapok]

0
likes
0
points
55
downloads

Publisher

verified publisherfeduke-nukem.dev

Weekly Downloads

Syntactic sugar for Dart. Extensions for List, Iterable, Duration and Future, plus Kotlin-style scope functions.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, meta

More

Packages that depend on caxapok