trough 1.0.0 copy "trough: ^1.0.0" to clipboard
trough: ^1.0.0 copied to clipboard

A middleware pipeline library for Dart, inspired by similar libraries in the JavaScript ecosystem. Create composable function pipelines for processing data in sequence.

example/trough_example.dart

import 'package:trough/trough.dart';

void main() {
  // Create a new pipeline
  final pipeline = trough();

  // Add middleware - multiply input by 2
  pipeline.use((List<dynamic> input, [Function? next]) {
    final value = input.isNotEmpty ? input[0] as int : 0;
    next?.call(null, [value * 2]);
    return null;
  });

  // Add another middleware - add 10
  pipeline.use((List<dynamic> input, [Function? next]) {
    final value = input.isNotEmpty ? input[0] as int : 0;
    next?.call(null, [value + 10]);
    return null;
  });

  // Run the pipeline
  pipeline.run([5], (Object? error, [List<dynamic>? output]) {
    if (error != null) {
      print('Error: $error');
    } else {
      print(
        'Result: ${output?.first}',
      ); // Should output: Result: 20 (5 * 2 + 10)
    }
  });

  // Synchronous middleware example
  final syncPipeline = trough();

  syncPipeline.use((List<dynamic> input, [Function? next]) {
    final text = input.isNotEmpty ? input[0] as String : '';
    return '$text World!';
  });

  syncPipeline.run(['Hello'], (Object? error, [List<dynamic>? output]) {
    if (error != null) {
      print('Error: $error');
    } else {
      print(
        'Sync result: ${output?.first}',
      ); // Should output: Sync result: Hello World!
    }
  });
}
0
likes
150
points
48
downloads

Publisher

unverified uploader

Weekly Downloads

A middleware pipeline library for Dart, inspired by similar libraries in the JavaScript ecosystem. Create composable function pipelines for processing data in sequence.

Repository (GitHub)
View/report issues

Topics

#middleware #pipeline #processing #functional #async

Documentation

Documentation
API reference

License

MIT (license)

More

Packages that depend on trough