mcpField
D
dart-logic-patterns

dart-logic-patterns

github.com/dhruvanbhalaraDevelopment30247 installsUpdated 8w ago
Repository

About dart-logic-patterns

A Dart coding skill covering algorithm efficiency and reusable business-logic patterns. It offers guidance on data structures, search and sorting, and keeping logic testable and responsive.

Key features

  1. 01Big O and data-structure guidance
  2. 02Debouncing, throttling, and memoization
  3. 03Dart 3 pattern matching
  4. 04Search and sorting approaches
  5. 05Pure functions and validation organization

Use cases

  1. 01Choosing structures for frequent lookups
  2. 02Reducing repeated work in interactive features
  3. 03Keeping validation reusable across screens

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/dhruvanbhalara/skills --skill dart-logic-patterns

After installing, type/dart-logic-patternsin Claude Code to confirm it loaded.

Details

From the project README

Algorithms & Logic

The efficiency of your business logic directly impacts battery life and responsiveness.

Complexity Analysis

  • Big O Awareness: Understand the cost of your operations. Avoid O(n²) or higher on the main thread for datasets larger than a few hundred items.
  • Data Structure Selection:
    • Map: Fast key-based lookups.
    • Set: Fast unique item management.
    • List: Fast indexing and sequential access.
    • LinkedHashSet/Map: Preserves insertion order while providing fast lookups.

Logic Patterns

  • Debouncing: Delay execution until a user stops interacting (e.g., search-as-you-type).
  • Throttling: Limit execution to at most once every interval (e.g., scrolling events).
  • Memoization: Cache the results of expensive pure functions based on their arguments. Use package:memoize or custom implementations.
  • Pattern Matching (Dart 3+): Use switch expressions and exhaustive pattern matching for control flow instead of deeply nested if-else chains. This is a core part of clean Dart logic.

Search & Sort

  • Binary Search: Use for sorted lists to transform O(n) searches into O(log n).
  • Efficient Sorting: Use Dart's built-in list.sort(), which uses highly optimized algorithms. Provide targeted Comparable implementations for custom objects.

Business Logic Organization

  • Pure Functions: Keep business logic in pure, testable functions outside of UI classes.
  • Fail Fast: Use guard clauses to handle edge cases and invalid states early.
  • Validation Logic: Keep complex validation in a separate domain layer, reusable across different screens.

Comments

Markdown supported