df_type 0.16.0 copy "df_type: ^0.16.0" to clipboard
df_type: ^0.16.0 copied to clipboard

Simplifies type conversions, inspections, nested data access, sync/async operations and more.

example/lib/example.dart

//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Copyright © dev-cetera.com & contributors.
//
// The use of this source code is governed by an MIT-style license described in
// the LICENSE file located in this project's root directory.
//
// See: https://opensource.org/license/mit
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~

// ignore_for_file: omit_local_variable_types, unreachable_switch_case

import 'dart:async';
import 'package:df_type/df_type.dart';

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

enum Alphabet { A, B, C }

enum Status { pending, active, done }

void main() async {
  // --- Type Checking ---
  print('\n*** Type Checking Utilities ***');
  print('isNullable<String?>: ${isNullable<String?>()}'); // true
  print('isSubtype<int, num>: ${isSubtype<int, num>()}'); // true
  print('typeEquality<int, int>: ${typeEquality<int, int>()}'); // true
  print('typeEquality<int, String>: ${typeEquality<int, String>()}'); // false

  // --- Type Conversion ---
  print('\n*** Type Conversion Utilities ***');
  print("letIntOrNull('55'): ${letIntOrNull('55')}"); // 55
  print(
    "letMapOrNull from JSON: ${letMapOrNull<String, dynamic>('{"a": 1}')}",
  ); // {a: 1}
  print(
    "letListOrNull from CSV: ${letListOrNull<int>('1, 2, 3')}",
  ); // [1, 2, 3]

  // --- Enum Helpers ---
  print('\n*** Enum Helpers ***');
  print(
    "Alphabet.values.valueOf('B'): ${Alphabet.values.valueOf('B')}",
  ); // Alphabet.B

  // --- Function and FutureOr Extensions ---
  print('\n*** Function and FutureOr Extensions ***');
  int Function(int) addOne = (i) => i + 1;
  print('Function.tryCall: ${addOne.tryCall<int, int>([5])}'); // 6

  FutureOr<int> futureOrValue = Future.value(10);
  print('futureOrValue.isFuture: ${futureOrValue.isFuture}'); // true
  print('futureOrValue.toFuture(): ${await futureOrValue.toFuture()}'); // 10

  // --- Asynchronous Helpers ---
  print('\n*** Asynchronous Helpers ***');
  // `consec` for handling a mix of sync/async values
  final result = await consec(Future.value(5), (val) => val * 2);
  print('consec result: $result'); // 10

  // `Waiter` for deferred, batched execution. Operations are stored as
  // immutable `WaiterOperation` value objects; `addFn` is the shortcut for
  // wrapping a bare function.
  final waiter = Waiter<String>()
    ..addFn(() => 'Task 1', id: 'task-1')
    ..addFn(() async => 'Task 2', id: 'task-2');
  final waiterResults = await waiter.wait();
  print('Waiter results: $waiterResults'); // (Task 1, Task 2)
}
4
likes
160
points
2.04k
downloads

Documentation

API reference

Publisher

verified publisherdev-cetera.com

Weekly Downloads

Simplifies type conversions, inspections, nested data access, sync/async operations and more.

Homepage
Repository (GitHub)
View/report issues

Topics

#data #easy-packages #tool #utility #utils

Funding

Consider supporting this project:

www.buymeacoffee.com
www.patreon.com
github.com

License

MIT (license)

Dependencies

collection, equatable

More

Packages that depend on df_type