safe_cast 1.0.2 copy "safe_cast: ^1.0.2" to clipboard
safe_cast: ^1.0.2 copied to clipboard

Dart library to provides safe way to cast objects or dynamics

Safe Cast #

Build Status Pub Pub Score License

  • Simple syntax
  • Reduces boillerplate
  • Does not throw like as T?

Usage #

import 'package:safe_cast/safe_cast.dart';
 ⋮
 Fruit? fruit = Cast.asNullable<Fruit>(maybeFruit);
 // or, if you need a fruit
 Fruit fruit = SafeCast.as<Fruit>(maybeFruit, ifNull: () => availableFruit());

How effective it is #

It is better for chained operations..

CuttedFruit? cutted = maybeFruit is Fruit ? maybeFruit.cut(fruitCutter) : null;
// intead of
CuttedFruit? cutted = Cast.asNullable<Fruit>(maybeFruit)?.cut(fruitCutter);

License #

The MIT License

0
likes
160
points
114
downloads

Publisher

verified publisherdig.dev.br

Weekly Downloads

Dart library to provides safe way to cast objects or dynamics

Repository (GitHub)
View/report issues

Topics

#null-safety #types #type-safe #type-safety

Documentation

API reference

License

MIT (license)

More

Packages that depend on safe_cast