MapObject constructor

MapObject({
  1. required Type type,
  2. required MapFunction function,
  3. MapObject? parent,
})

A configurable value transformer that applies type-specific mapping rules to objects.

This implements a chainable transformation pipeline that:

  1. Processes values through parent mappings first (if any)
  2. Applies type-specific transformations
  3. Preserves unmapped types unchanged

Core Features:

  • Type-Specific Handling: Different transformations per type
  • Chained Execution: Parent-child mapping composition
  • Null Safety: Handles null inputs gracefully
  • Immutability: All mappings are final after creation

Example Usage:

// Create mapper for specific types
final mapper = MapObject(
  type: String,
  function: (s) => s.toUpperCase(),
  parent: anotherMapper
);

// Apply transformations
mapper(123); // Returns 123 (unchanged)
mapper('text'); // Returns 'TEXT'

Implementation

MapObject({required Type type, required MapFunction function, MapObject? parent})
    : map = Map.unmodifiable(<Type,MapFunction>{type: function}), parent = parent is MapObject ? parent : null;