pure
1.0.0, released 8 months ago by yakov.codes
Functional programming essentials for Dart with composition, memoization, and trampolines.
What it does
Brings functional programming features to Dart through extension methods, including function composition, pipes, constant values, currying, flipping, nullable invocation, stack-safe recursion trampolines, and memoization. It also provides basic functions and a TaggedRecord base class for product and sum types.
AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to use function composition or pipes to reduce code nesting.
- You need stack-safe recursion via trampolines to prevent stack overflow.
- You want to memoize function results or use weak memoization for object keys.
Skip it when
- You prefer a strictly object-oriented or procedural programming style without functional patterns.
- You need a comprehensive state management framework instead of core utility helpers.
Strengths
- Provides tail call optimization and stack-safe recursion.
- Supports up to 9 arguments for extensions like composition and currying.
- Includes both strong and weak memoization capabilities.
Weaknesses
- Can make code harder to read for developers unfamiliar with functional programming idioms.
- Using memoization on impure functions leads to unexpected behavior.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
double intToDouble(int x) => x.toDouble();
String doubleToString(double x) => x.toString();
final intToStringComposition = doubleToString.dot(intToDouble);
String intToStringPipe(int x) => x.pipe(intToDouble).pipe(doubleToString);Alternatives
Packages that do the same job and could replace pure.
- dart_either
Either monad for Dart and Flutter supporting type-safe error handling and railway-oriented programming.
81Compare - fpdart
Functional programming types and patterns for Dart and Flutter.
71Compare - dartz
Functional programming library with monads, immutable collections, and combinators for Dart
50Compare - structured_async
Structured asynchronous programming and cancellable futures for Dart.
39Compare