-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
569 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# IntelliJ files | ||
.idea/ | ||
|
||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
# Remove the following pattern if you wish to check in your lock file | ||
pubspec.lock | ||
|
||
# Conventional directory for build outputs | ||
build/ | ||
|
||
# Directory created by dartdoc | ||
doc/api/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: dart | ||
sudo: required | ||
dist: bionic | ||
|
||
dart: | ||
- stable | ||
|
||
script: | ||
- dartanalyzer --fatal-warnings lib | ||
- pub run test test --platform vm | ||
- pub run test_coverage | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## 1.0.1 - Fix me up, Scotty | ||
|
||
- Fix `GlobalDateTime.now()` returning the incorrect date and time. | ||
|
||
|
||
## 1.0.0 - Initial Launch! 🚀 | ||
|
||
- Add collection library | ||
- Add core library | ||
- Add time library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 - 2020 Forus Labs | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Sane: Forus Labs' Core Dart Library | ||
[](https://travis-ci.com/forus-labs/sane) | ||
[](https://codecov.io/gh/forus-labs/sane) | ||
[](https://pub.dev/packages/sane) | ||
|
||
Sane is Forus Labs' core library that includes annotations, collection types, date-times and utilities for numerics and strings. | ||
|
||
**This is a bleeding edge version of Sane. For a production ready and documented version, please refer to the [stable branch](https://github.com/forus-labs/sane/tree/stable).** | ||
|
||
|
||
### [`sane.collection`](https://pub.dev/documentation/sane/latest/sane.collection/sane.collection-library.html) | ||
|
||
* Delegating collection types | ||
* Observable collection types | ||
* Tuples (`Pair`, `Triple` and `Quad`) | ||
* Pseudo-weak collection types | ||
|
||
### [`sane.core`](https://pub.dev/documentation/sane/latest/sane.core/sane.core-library.html) | ||
|
||
* Annotations (i.e. `nullable`, `tainted`) | ||
* Pseudo-weak reference | ||
* Utilities for numerics and strings | ||
|
||
### [`sane.time`](https://pub.dev/documentation/sane/latest/sane.time/sane.time-library.html) | ||
|
||
* Distinct global and localized date-time types | ||
* `Period` type | ||
* `Span` type | ||
* `Time` type | ||
* Utilities for rounding date-times | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:flint/analysis_options.dart.dev.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**Please refer to the [wiki](https://github.com/forus-labs/sane/wiki).** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: sane_example | ||
description: Example for sane | ||
private: true | ||
version: 1.0.0 | ||
homepage: https://github.com/forus-labs/cauldron | ||
repository: https://github.com/forus-labs/cauldron | ||
|
||
environment: | ||
sdk: '>=2.8.4 <3.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library sugar.collection; | ||
|
||
export 'src/collection/equality.dart'; | ||
export 'src/collection/fluent_iterable.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
library sugar.core; | ||
|
||
export 'src/core/equality.dart'; | ||
export 'src/core/math.dart'; | ||
export 'src/core/types.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
extension ListEquality<T> on List<T> { | ||
|
||
bool equals(List<T> other) { | ||
if (identical(this, other)) { | ||
return true; | ||
} | ||
|
||
if (length != other.length) { | ||
return false; | ||
} | ||
|
||
for (var i = 0; i < length; i++) { | ||
if ([i] != other[i]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} | ||
|
||
extension MapEquality<K, V> on Map<K, V> { | ||
|
||
bool equals(Map<K, V> other) { | ||
if (identical(this, other)) { | ||
return true; | ||
} | ||
|
||
if (length != other.length) { | ||
return false; | ||
} | ||
|
||
for (final entry in entries) { | ||
if (entry.value != other[entry.key]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} | ||
|
||
extension SetEquality<T> on Set<T> { | ||
|
||
bool equals(Set<T> other) => identical(this, other) || (length == other.length && containsAll(other)); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
extension FluentIterable<T> on Iterable<T> { | ||
|
||
Iterable<T> distinct() sync* { | ||
for (final element in toSet()) { | ||
yield element; | ||
} | ||
} | ||
|
||
Iterable<T> listen(void Function(T) listen) sync* { | ||
for (final element in this) { | ||
listen(element); | ||
yield element; | ||
} | ||
} | ||
|
||
Iterable<T> mapWhere(bool Function(T) predicate, T Function(T) replace) sync* { | ||
for (final element in this) { | ||
if (predicate(element)) { | ||
yield replace(element); | ||
|
||
} else { | ||
yield element; | ||
} | ||
} | ||
} | ||
|
||
|
||
Iterable<MapEntry<int, T>> indexed({int initial = 0}) sync* { | ||
for (final element in this) { | ||
yield MapEntry(initial++, element); | ||
} | ||
} | ||
|
||
|
||
bool none(bool Function(T) predicate) { | ||
for (final element in this) { | ||
if (predicate(element)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
Map<K, V> toMap<K, V>(K Function(T) key, V Function(T) value) => { | ||
for (final element in this) | ||
key(element) : value(element) | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'package:sugar/core.dart'; | ||
|
||
typedef Apply<T, R> = R Function(T value); | ||
|
||
|
||
@immutable class Pair<K, V> with Equality implements MapEntry<K, V> { | ||
|
||
@override final K key; | ||
@override final V value; | ||
@override final List<dynamic> fields; | ||
|
||
Pair(this.key, this.value): fields = List.unmodifiable([key, value]); | ||
|
||
|
||
Pair<K, V> replace({K key, V value}) => Pair(key ?? this.key, value ?? this.value); | ||
|
||
Pair<K1, V1> map<K1, V1>(Apply<K, K1> key, Apply<V, V1> value) => Pair(key(this.key), value(this.value)); | ||
|
||
T reduce<T>(T Function(K, V) reduce) => reduce(key, value); | ||
|
||
} | ||
|
||
@immutable class Triple<L, M, R> with Equality { | ||
|
||
final L left; | ||
final M middle; | ||
final R right; | ||
@override final List<dynamic> fields; | ||
|
||
Triple(this.left, this.middle, this.right): fields = List.unmodifiable([left, middle, right]); | ||
|
||
|
||
Triple<L, M, R> replace({L left, M middle, R right}) => Triple(left ?? this.left, middle ?? this.middle, right ?? this.right); | ||
|
||
Triple<L1, M1, R1> map<L1, M1, R1>(Apply<L, L1> left, Apply<M, M1> middle, Apply<R, R1> right) => Triple(left(this.left), middle(this.middle), right(this.right)); | ||
|
||
T reduce<T>(T Function(L, M, R) reduce) => reduce(left, middle, right); | ||
|
||
} | ||
|
||
@immutable class Quad<T1, T2, T3, T4> with Equality { | ||
|
||
final T1 first; | ||
final T2 second; | ||
final T3 third; | ||
final T4 fourth; | ||
@override final List<dynamic> fields; | ||
|
||
Quad(this.first, this.second, this.third, this.fourth): fields = List.unmodifiable([first, second, third, fourth]); | ||
|
||
|
||
Quad<T1, T2, T3, T4> replace({T1 first, T2 second, T3 third, T4 fourth}) => Quad(first ?? this.first, second ?? this.second, third ?? this.third, fourth ?? fourth); | ||
|
||
Quad<R1, R2, R3, R4> map<R1, R2, R3, R4>(Apply<T1, R1> first, Apply<T2, R2> second, Apply<T3, R3> third, Apply<T4, R4> fourth) | ||
=> Quad(first(this.first), second(this.second), third(this.third), fourth(this.fourth)); | ||
|
||
T reduce<T>(T Function(T1, T2, T3, T4) reduce) => reduce(first, second, third, fourth); | ||
|
||
} | ||
|
||
|
||
extension TupleIterable on Iterable<Iterable<dynamic>> { | ||
|
||
Iterable<Pair<K, V>> pairs<K, V>() sync* { | ||
for (final iterable in this) { | ||
if (iterable.length == 2) { | ||
yield Pair<K, V>(iterable.elementAt(0), iterable.elementAt(1)); | ||
|
||
} else { | ||
throw ArgumentError.value(iterable, 'Pair has a length of: ${iterable.length}, should be 2'); | ||
} | ||
} | ||
} | ||
|
||
Iterable<Triple<L, M, R>> triples<L, M, R>() sync* { | ||
for (final iterable in this) { | ||
if (iterable.length == 3) { | ||
yield Triple<L, M, R>(iterable.elementAt(0), iterable.elementAt(1), iterable.elementAt(2)); | ||
|
||
} else { | ||
throw ArgumentError.value(iterable, 'Triple has a length of: ${iterable.length}, should be 3'); | ||
} | ||
} | ||
} | ||
|
||
Iterable<Quad<T1, T2, T3, T4>> quads<T1, T2, T3, T4>() sync* { | ||
for (final iterable in this) { | ||
if (iterable.length == 4) { | ||
yield Quad<T1, T2, T3, T4>(iterable.elementAt(0), iterable.elementAt(1), iterable.elementAt(2), iterable.elementAt(4)); | ||
|
||
} else { | ||
throw ArgumentError.value(iterable, 'Quad has a length of: ${iterable.length}, should be 4'); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'package:sugar/collection.dart'; | ||
import 'package:sugar/core.dart'; | ||
|
||
mixin Equality { | ||
|
||
@override | ||
bool operator == (dynamic other) => identical(this, other) || (other.subclassOf(this) && fields.equals(other.fields)); | ||
|
||
@override | ||
int get hashCode => hash(fields); | ||
|
||
@override | ||
String toString() => '$runtimeType(${fields.join(', ')})'; | ||
|
||
|
||
@protected List<dynamic> get fields; | ||
|
||
} |
Oops, something went wrong.