From 0873f3e18667d60f51b82ffe7baaa2a0d7ee4d71 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 15 Sep 2016 23:32:51 -0700 Subject: [PATCH] Move maxBy into the MaterialArc file (#5905) As per our style guide, if you can't explain something, refactor it. I studied this function for a while and still can't explain it, so... --- .../lib/src/foundation/basic_types.dart | 18 ------------------ packages/flutter/lib/src/material/arc.dart | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/packages/flutter/lib/src/foundation/basic_types.dart b/packages/flutter/lib/src/foundation/basic_types.dart index a6d2ec009e..1884faabc8 100644 --- a/packages/flutter/lib/src/foundation/basic_types.dart +++ b/packages/flutter/lib/src/foundation/basic_types.dart @@ -243,21 +243,3 @@ class _LazyListIterator implements Iterator { return true; } } - -// COLLECTION UTILITIES - -typedef dynamic KeyFunc(T input); - -/// Select the element for which the key function returns the maximum value. -dynamic/*=T*/ maxBy/**/(Iterable input, KeyFunc/**/ keyFunc) { - dynamic/*=T*/ maxValue; - dynamic maxKey; - for (dynamic/*=T*/ value in input) { - dynamic key = keyFunc(value); - if (maxKey == null || key > maxKey) { - maxValue = value; - maxKey = key; - } - } - return maxValue; -} diff --git a/packages/flutter/lib/src/material/arc.dart b/packages/flutter/lib/src/material/arc.dart index 46820c1997..90422cf032 100644 --- a/packages/flutter/lib/src/material/arc.dart +++ b/packages/flutter/lib/src/material/arc.dart @@ -5,7 +5,6 @@ import 'dart:math' as math; import 'dart:ui' show hashValues, lerpDouble; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:meta/meta.dart'; @@ -160,6 +159,22 @@ const List<_Diagonal> _allDiagonals = const <_Diagonal>[ const _Diagonal(_CornerId.bottomLeft, _CornerId.topRight), ]; +typedef dynamic _KeyFunc(T input); + +// Select the element for which the key function returns the maximum value. +dynamic/*=T*/ _maxBy/**/(Iterable input, _KeyFunc/**/ keyFunc) { + dynamic/*=T*/ maxValue; + dynamic maxKey; + for (dynamic/*=T*/ value in input) { + dynamic key = keyFunc(value); + if (maxKey == null || key > maxKey) { + maxValue = value; + maxKey = key; + } + } + return maxValue; +} + /// A [Tween] that animates a [Rect] from [begin] to [end]. /// /// The rectangle corners whose diagonal is closest to the overall direction of @@ -184,7 +199,7 @@ class MaterialRectArcTween extends RectTween { assert(begin != null); assert(end != null); final Offset centersVector = end.center - begin.center; - _diagonal = maxBy(_allDiagonals, (_Diagonal d) => _diagonalSupport(centersVector, d)); + _diagonal = _maxBy/*<_Diagonal>*/(_allDiagonals, (_Diagonal d) => _diagonalSupport(centersVector, d)); _beginArc = new MaterialPointArcTween( begin: _cornerFor(begin, _diagonal.beginId), end: _cornerFor(end, _diagonal.beginId)