| OLD | NEW |
| 1 // | 1 // |
| 2 // Copyright 2014 Google Inc. All rights reserved. | 2 // Copyright 2014 Google Inc. All rights reserved. |
| 3 // | 3 // |
| 4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
| 5 // license that can be found in the LICENSE file or at | 5 // license that can be found in the LICENSE file or at |
| 6 // https://developers.google.com/open-source/licenses/bsd | 6 // https://developers.google.com/open-source/licenses/bsd |
| 7 // | 7 // |
| 8 | 8 |
| 9 part of charted.core.utils; | 9 part of charted.core.utils; |
| 10 | 10 |
| 11 /// Returns a sum of all values in the given list of values | 11 /// Returns a sum of all values in the given list of values |
| 12 num sum(List values) => values == null || values.isEmpty | 12 num sum(List values) => values == null || values.isEmpty |
| 13 ? 0 | 13 ? 0 |
| 14 : values.fold(0.0, (old, next) => old + next); | 14 : values.fold(0.0, (old, next) => old + next); |
| 15 | 15 |
| 16 /// Returns the smallest number in the given list of values | 16 /// Returns the smallest number in the given list of values |
| 17 num min(Iterable values) => values == null || values.isEmpty | 17 num min(Iterable<num> values) => values == null || values.isEmpty |
| 18 ? null | 18 ? null |
| 19 : values.fold(values.elementAt(0), math.min); | 19 : values.fold(values.elementAt(0), (x, y) => math.min(x, y)); |
| 20 | 20 |
| 21 /// Returns the largest number in the given list of values | 21 /// Returns the largest number in the given list of values |
| 22 num max(Iterable values) => values == null || values.isEmpty | 22 num max(Iterable<num> values) => values == null || values.isEmpty |
| 23 ? null | 23 ? null |
| 24 : values.fold(values.elementAt(0), math.max); | 24 : values.fold(values.elementAt(0), (x, y) => math.max(x, y)); |
| 25 | 25 |
| 26 /// Represents a constant pair of values | 26 /// Represents a constant pair of values |
| 27 class Pair<T1, T2> { | 27 class Pair<T1, T2> { |
| 28 final T1 first; | 28 final T1 first; |
| 29 final T2 last; | 29 final T2 last; |
| 30 | 30 |
| 31 const Pair(this.first, this.last); | 31 const Pair(this.first, this.last); |
| 32 | 32 |
| 33 bool operator ==(other) => | 33 bool operator ==(other) => |
| 34 other is Pair && first == other.first && last == other.last; | 34 other is Pair && first == other.first && last == other.last; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 : super(values); | 103 : super(values); |
| 104 | 104 |
| 105 static int _integerConversionFactor(num val) { | 105 static int _integerConversionFactor(num val) { |
| 106 int k = 1; | 106 int k = 1; |
| 107 while (val * k % 1 > 0) { | 107 while (val * k % 1 > 0) { |
| 108 k *= 10; | 108 k *= 10; |
| 109 } | 109 } |
| 110 return k; | 110 return k; |
| 111 } | 111 } |
| 112 } | 112 } |
| OLD | NEW |