when_expression 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new59

when™ v1.0.0 #

Overview #

  • Wanted some functional programming in Dart?
  • Realised that the only way not to use ifs and switches is ternary operatiors?

Something has gone wrong #

Now Check This!® #

How to use this super-awesome super-helpful super-non-flutter-way library© #

  1. Use pub.dev to get this s-a s-h s-n-f-w library©
dependencies:
  when_expression: ^1.0.0
  1. Define when™ statement
final myWhenStatement = when<int, String>({
  (v) => v == 1: (_) => "a",
  (v) => v == 2: (_) => "b",
  (v) => v == 2: (_) => "c",
  (v) => v == 4: (_) => "d",
  (v) => true: (_) => "you're a failure"
});
  1. Be aware!
final myWhenStatement = when<int, String>({
  (v) => v == 1: (_) => "a",
  (v) => v == 2: (_) => "b", // This one will work
  (v) => v == 2: (_) => "c", // This one will never be handled
  (v) => v == 4: (_) => "d",
  (v) => true: (_) => "you're a failure" // if your value is not handled if previous parts
                                         // you should define else statement
});
  1. Call it!
print("out: ${myWhenStatement(1)}") // out: a
print("out: ${myWhenStatement(2)}") // out: b
print("out: ${myWhenStatement(10000)}") // out: you're a failure

//This won't compile
print("out: ${myWhenStatement('-1.0')}")

Credits: #

  • My righteous anger at Dart for its so-called simplicity (Really, you've made this wrong, congrats, dart devs!)

[1.0.0] - Initial release. #

  • woooow! when is not available in dart
  • omg!!

[1.0.1] - Fixes. #

  • I've never thought that pub.dev requirements are so stubborn and inadequate

example/README.md

when_example #

A new Flutter package project.

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  when_expression: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:when_expression/when_expression.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
18
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • when_expression that is a package requiring null.

Health suggestions

Format lib/when_expression.dart.

Run flutter format to format lib/when_expression.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test