# abstract_dart #

A collection of algebraic structures borrowed from abstract algebra. Semigroup, Monoid, Group, Field, and more.

Example:

``````/// Create a semigroup
final semigroup = Semigroup_.create<double>((a, b) => a + b);

/// Create a monoid
final monoid = Monoid_.create<double>(() => 0.0, (a, b) => a + b);

/// Create a group
final group =
Group_.create<double>(() => 0.0, (a, b) => a + b, (a, b) => a - b);

/// Create a field
final field = Field_.create<double>(
Group_.create<double>(() => 0.0, (a, b) => a + b, (a, b) => a - b),
Group_.create<double>(() => 1.0, (a, b) => a * b, (a, b) => a / b),
);

/// Monoids
const bigIntSumMonoid = BigIntSumMonoid();
const bigIntProductMonoid = BigIntProductMonoid();
const decimalSumMonoid = DecimalSumMonoid();
const decimalProductMonoid = DecimalProductMonoid();
const stringConcatMonoid = StringConcatMonoid();
const numSumMonoid = NumSumMonoid();
const numProductMonoid = NumProductMonoid();
const intSumMonoid = IntSumMonoid();
const intProductMonoid = IntProductMonoid();
const doubleSumMonoid = DoubleSumMonoid();
const doubleProductMonoid = DoubleProductMonoid();

/// Groups
const bigIntSumGroup = BigIntSumGroup();
const decimalSumGroup = DecimalSumGroup();
const decimalProductGroup = DecimalProductGroup();
const doubleProductGroup = DoubleProductGroup();
const doubleSumGroup = DoubleSumGroup();
const numProductGroup = NumProductGroup();
const numSumGroup = NumSumGroup();

/// Fields
const decimalField = DecimalField();
const doubleField = DoubleField();
const numField = NumField();
``````

#### `Semigroup_<A>`#

• An operation of type A+A => A

#### `Monoid_<A>` (a `Semigroup_<A>`)

• An operation of type A+A => A
• An identity element so that a+e = a

#### `Group_<A>` (a `Monoid_<A>`, a `Semigroup_<A>`)

• An operation of type A+A => A
• An inverse operation of type A-A => A
• An identity element so that a+e = a

#### `ScalarMonoid_<K, F>` #

• An operation of type K•F => K
• An identity element so that K•e = K

#### `VectorSpace_<K, F>`#

• A Group
• A ScalarMonoid<K, F> (scalar multiplication)

#### `Algebra_<K, F>` (a `VectorSpace_<K, F>`, a `Field_<K>`)

• A Group
• A Group
• A ScalarMonoid<K, F> (scalar multiplication)

abstract_dart does not enforce any of the properties that these structures require in a mathematical setting.

## 1.0.2 (2019-11-12) #

• ScalarMonoid_, VectorSpace_ & Algebra_ added
• DurationVectorSpace, DurationScalarMonoid, DurationSumGroup and DurationSumMonoid added

## 1.0.0 (2019-11-03) #

• complete rewrite, 100% coverage

## 0.0.1 (2019-08-17) #

• Initial version

example/main.dart

``````import 'package:abstract_dart/abstract_dart.dart';

void main() {
/// Create a semigroup
final semigroup = Semigroup_.create<double>((a, b) => a + b);

/// Create a monoid
final monoid = Monoid_.create<double>(() => 0.0, (a, b) => a + b);

/// Create a group
final group =
Group_.create<double>(() => 0.0, (a, b) => a + b, (a, b) => a - b);

/// Create a field
final field = Field_.create<double>(
Group_.create<double>(() => 0.0, (a, b) => a + b, (a, b) => a - b),
Group_.create<double>(() => 1.0, (a, b) => a * b, (a, b) => a / b),
);

/// Monoids
const bigIntSumMonoid = BigIntSumMonoid();
const bigIntProductMonoid = BigIntProductMonoid();
const decimalSumMonoid = DecimalSumMonoid();
const decimalProductMonoid = DecimalProductMonoid();
const stringConcatMonoid = StringConcatMonoid();
const numSumMonoid = NumSumMonoid();
const numProductMonoid = NumProductMonoid();
const intSumMonoid = IntSumMonoid();
const intProductMonoid = IntProductMonoid();
const doubleSumMonoid = DoubleSumMonoid();
const doubleProductMonoid = DoubleProductMonoid();

/// Groups
const intSumGroup = IntSumGroup();
const bigIntSumGroup = BigIntSumGroup();
const decimalSumGroup = DecimalSumGroup();
const decimalProductGroup = DecimalProductGroup();
const doubleProductGroup = DoubleProductGroup();
const doubleSumGroup = DoubleSumGroup();
const numProductGroup = NumProductGroup();
const numSumGroup = NumSumGroup();

/// Fields
const decimalField = DecimalField();
const doubleField = DoubleField();
const numField = NumField();

/// To suppress the unused warnings
final _ = [
semigroup,
monoid,
group,
field,
intSumGroup,
bigIntSumMonoid,
bigIntProductMonoid,
decimalSumMonoid,
decimalProductMonoid,
stringConcatMonoid,
numSumMonoid,
numProductMonoid,
intSumMonoid,
intProductMonoid,
doubleSumMonoid,
doubleProductMonoid,
bigIntSumGroup,
decimalSumGroup,
decimalProductGroup,
decimalProductGroup,
doubleProductGroup,
doubleSumGroup,
numProductGroup,
numSumGroup,
decimalField,
doubleField,
numField,
];
}
``````

## Use this package as a library

### 1. Depend on it

``````
dependencies:
abstract_dart: ^1.0.2

``````

### 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:abstract_dart/abstract_dart.dart';
``````
 Popularity: Describes how popular the package is relative to other packages. [more] 39 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] 69

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

• Dart: 2.7.0
• pana: 0.13.4

#### Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.4 <3.0.0
decimal ^0.3.5 0.3.5
Transitive dependencies
rational 0.3.7
Dev dependencies
extra_pedantic ^1.1.1+3
test ^1.6.6
test_coverage ^0.2.0