Skip to content
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6db1ddc
Remove duplicate test file
ajayi-joseph Jan 2, 2026
bd94358
Add tests for component utilities: forwardRef2, memo2, and Children u…
ajayi-joseph Jan 2, 2026
cb37276
Add tests for component composition functionality
ajayi-joseph Jan 2, 2026
fa44e8b
Add tests for conditional and list rendering functionality
ajayi-joseph Jan 2, 2026
6a508d0
Add tests for HTML elements rendering functionality
ajayi-joseph Jan 2, 2026
4aee923
Add tests for special components: Fragment and StrictMode, and utilit…
ajayi-joseph Jan 2, 2026
35e5a33
Add tests for event handling functionality including click, focus, an…
ajayi-joseph Jan 2, 2026
ae63da6
Add tests for createRef functionality
ajayi-joseph Jan 2, 2026
2feae55
Add tests for useCallback hook functionality
ajayi-joseph Jan 2, 2026
b406bf6
Add tests for useContext hook functionality
ajayi-joseph Jan 2, 2026
2cf99dd
Add tests for useLayoutEffect hook functionality
ajayi-joseph Jan 2, 2026
72f3a4e
Add tests for useEffect hook functionality
ajayi-joseph Jan 2, 2026
5494605
Add tests for useMemo hook functionality
ajayi-joseph Jan 2, 2026
92c4138
Add tests for useReducerLazy hook functionality
ajayi-joseph Jan 2, 2026
34131eb
Add tests for useReducer hook functionality
ajayi-joseph Jan 2, 2026
c97af8e
Add tests for useRef hook functionality
ajayi-joseph Jan 2, 2026
222a96d
Add tests for useStateJSArray hook functionality
ajayi-joseph Jan 2, 2026
d9b7988
Add tests for useStateLazy hook functionality
ajayi-joseph Jan 2, 2026
3cf9767
Add tests for useState hook functionality
ajayi-joseph Jan 2, 2026
1348b8c
Add tests for JSX DSL functionality
ajayi-joseph Jan 2, 2026
d5e688a
Remove use_state_js_test after break down
ajayi-joseph Jan 2, 2026
3249c28
Merge branch 'main' into main
MelbourneDeveloper Jan 17, 2026
1a14d6a
Merge branch 'MelbourneDeveloper:main' into main
ajayi-joseph Jan 21, 2026
007eec8
docs: enhance FP extensions documentation
ajayi-joseph Jan 21, 2026
0d38f83
docs: fix formatting issues in extensions documentation
ajayi-joseph Jan 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 61 additions & 3 deletions packages/dart_node_core/lib/src/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,73 @@
/// Extension methods FP style transformations
/// Functional programming extensions for nullable and non-null types.
///
/// Provides pattern matching and transformation utilities inspired by
/// functional programming languages like Kotlin and Rust.
library;

/// Extension methods for nullable values enabling pattern matching and
/// functional transformations.
///
/// Example:
/// ```dart
/// String? getName() => 'World';
///
/// final greeting = getName().match(
/// some: (name) => 'Hello, $name!',
/// none: () => 'Hello, stranger!',
/// );
/// ```
extension NullableExtensions<T extends Object> on T? {
/// Pattern match on nullable value with cases for non-null and null.
///
/// This provides a safe way to handle nullable values by requiring
/// explicit handling of both the present (`some`) and absent (`none`) cases.
///
/// **Parameters:**
/// - `some`: Function called when this value is non-null
/// - `none`: Function called when this value is null
///
/// **Returns:** The result of calling either `some` or `none`
///
/// Example:
/// ```dart
/// int? maybeNumber = 42;
///
/// final result = maybeNumber.match(
/// some: (n) => 'Number: $n',
/// none: () => 'No number',
/// ); // Returns: "Number: 42"
/// ```
R match<R>({required R Function(T) some, required R Function() none}) =>
switch (this) {
final T value => some(value),
null => none(),
};
}

/// Extension methods FP style transformations
/// Extension methods for non-null values enabling functional transformations.
///
/// Provides utilities for applying transformations to values in a functional style.
extension ObjectExtensions<T extends Object> on T {
/// Apply function [op] to this value if non-null and return the result.
/// Apply function [op] to this value and return the result.
///
/// This is useful for chaining operations and avoiding temporary variables.
/// Also known as the "let" operation in Kotlin or "tap" in other languages.
///
/// **Parameters:**
/// - `op`: Function that transforms this value into a result of type `R`
///
/// **Returns:** The result of calling `op` with this value
///
/// Example:
/// ```dart
/// final length = 'hello world'
/// .let((s) => s.split(' '))
/// .let((words) => words.length); // Returns: 2
///
/// // Instead of:
/// final text = 'hello world';
/// final words = text.split(' ');
/// final length = words.length;
/// ```
R let<R>(R Function(T) op) => op(this);
}