dfunc 0.4.2+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

Functional batteries for Dart programming language.

Provides implementation of Optional, Either and other types + some helper functions.

Usage #

A simple usage example:

import 'package:built_value/built_value.dart';
import 'package:dfunc/dfunc.dart';

part 'main.g.dart';

void main() {
  final items = ['a', 'b', 'c'];
  print('mapped: ${mapIndexed((i, e) => '$e$i', items)}');

  // Sealed classes generation:

  final item = Base.item1((b) => b..text = 'TEST');
  item.fold((item) => print(item.text), (_) => print('2')); // prints TEST

  final state = State.state2();
  state.fold(
    (_) => print('1'),
    (_) => print('2'),
    (_) => print('3'),
  ); // prints 2

  // Optional

  final optional = Optional.of('test');
  optional.isEmpty() == false;
  optional.getOrNull() == 'test';

  // Either

  final either = Either<Exception, String>.right('test');
  either.isRight() == true;
  either.map((s) => s.toUpperCase()).right == 'TEST';
}

class Base extends Coproduct2<Item1, Item2> {
  Base.item1([Function(Item1Builder b) updates]) : super.item1(Item1(updates));

  const Base.item2() : super.item2(const Item2());
}

/// Can be used together with built_value library to create
/// immutable cases.
abstract class Item1 implements Built<Item1, Item1Builder> {
  factory Item1([Function(Item1Builder b) updates]) = _$Item1;

  Item1._();

  String get text;
}

class Item2 {
  const Item2();
}

class State extends Coproduct3<State1, State2, State3> {
  const State.state1() : super.item1(const State1());

  const State.state2() : super.item2(const State2());

  const State.state3() : super.item3(const State3());
}

class State1 {
  const State1();
}

class State2 {
  const State2();
}

class State3 {
  const State3();
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.4.2+1 #

  • Fixed Coproduct::fold

0.4.2 #

  • Added Coproduct6

0.4.1 #

  • Added Coproduct::toString

0.4.0 #

  • Simplified API, removed sealed. A lot of breaking changes!

0.3.6 #

  • Added zip2 and zipWith functions

0.3.5 #

  • Added extensions
  • Added Coproduct up to Coproduct10

0.3.4 #

  • Updated README.

0.3.3 #

  • Added some examples.

0.3.2 #

  • Added @sealed annotation

0.3.1 #

  • Added Sealed annotation

0.3.0 #

  • Either now throws StateError for wrong branch
  • Added const constructors to Either and Optional
  • Added == for Either

0.2.1 #

  • Exported Eithers functions

0.2.0 #

  • Added Eithers::combine*
  • Renamed Either::combine2 to Either::combine

0.1.11 #

  • Fixed dependencies
  • Fix analyzer issues

0.1.10 #

  • Added Product type
  • Added Coproduct type
  • Added Either::combine2 function

0.1.9 #

  • Added Optional::where function

0.1.8 #

  • Exported Optional

0.1.7 #

  • Added toOptional() extension method

0.1.6 #

  • Added Optional

0.1.5 #

  • Fixed error in Future

0.1.4 #

  • Added Future
  • FutureEitherExtension functions parameters now return FutureOr

0.1.3 #

  • Added Either::mapAsync function

0.1.2 #

  • Added Either::map function

0.1.1 #

  • Added Either extensions

0.1.0 #

  • Depends on Dart 2.6.0
  • Added Either

0.0.7 #

  • Make sum func generic
  • Added pipe functions

0.0.6 #

  • Added functions:
    • ignore
    • always
    • T
    • F
    • substring
    • limit

0.0.5 #

  • Added functions:
    • map
    • complement
    • isEmpty

0.0.4 #

  • Updated description

0.0.3 #

  • Updated documentation
  • Added tests

0.0.2 #

  • Initial version

example/lib/main.dart

import 'package:built_value/built_value.dart';
import 'package:dfunc/dfunc.dart';

part 'main.g.dart';

void main() {
  final items = ['a', 'b', 'c'];
  print('mapped: ${mapIndexed((i, e) => '$e$i', items)}');

  // Sealed classes generation:

  final item = Base.item1((b) => b..text = 'TEST');
  item.fold((item) => print(item.text), (_) => print('2')); // prints TEST

  final state = State.state2();
  state.fold(
    (_) => print('1'),
    (_) => print('2'),
    (_) => print('3'),
  ); // prints 2

  // Optional

  final optional = Optional.of('test');
  optional.isEmpty() == false;
  optional.getOrNull() == 'test';

  // Either

  final either = Either<Exception, String>.right('test');
  either.isRight() == true;
  either.map((s) => s.toUpperCase()).right == 'TEST';
}

class Base extends Coproduct2<Item1, Item2> {
  Base.item1([Function(Item1Builder b) updates]) : super.item1(Item1(updates));

  const Base.item2() : super.item2(const Item2());
}

/// Can be used together with built_value library to create
/// immutable cases.
abstract class Item1 implements Built<Item1, Item1Builder> {
  factory Item1([Function(Item1Builder b) updates]) = _$Item1;

  Item1._();

  String get text;
}

class Item2 {
  const Item2();
}

class State extends Coproduct3<State1, State2, State3> {
  const State.state1() : super.item1(const State1());

  const State.state2() : super.item2(const State2());

  const State.state3() : super.item3(const State3());
}

class State1 {
  const State1();
}

class State2 {
  const State2();
}

class State3 {
  const State3();
}

Use this package as a library

1. Depend on it

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


dependencies:
  dfunc: ^0.4.2+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:dfunc/dfunc.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
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]
80
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
quiver >=2.0.0 <3.0.0 2.1.3
Transitive dependencies
matcher 0.12.8
meta 1.1.8
path 1.7.0
stack_trace 1.9.5
Dev dependencies
pedantic ^1.7.0
test ^1.6.0