Repository: more-itertools/more-itertools (python)

Issue:
One more nit on all_equal()
I missed something during the code review.  There is an extra unnecessary `next` call in the first for-loop.  This is easily solved by adding another `return True`.

```
def all_equal(iterable, key=None):
    iterator = groupby(iterable, key)
    for first in iterator:
        for second in iterator:
            return False
        return True                          # <== This was missed
    return True
```

For example, `all_equal('a')` calls the `groupby.__next__` three times.

This is can be made visible by replacing `groupby` with `verbose_groupby`:

```
class verbose_groupby(itertools.groupby):

    def __next__(self):
        print('N')
        return super().__next__()
```


Pull request description:
Reduce groupby.__next__ calls in all_equal
This PR implements @rhettinger's suggestion in issue 902.

Closes #902 

Patch:
diff --git a/more_itertools/recipes.py b/more_itertools/recipes.py
index f7db03b..67f76fa 100644
--- a/more_itertools/recipes.py
+++ b/more_itertools/recipes.py
@@ -222,6 +222,7 @@ def all_equal(iterable, key=None):
     for first in iterator:
         for second in iterator:
             return False
+        return True
     return True
 
 


Test patch:
diff --git a/tests/test_recipes.py b/tests/test_recipes.py
index d3762d4..684a6fc 100644
--- a/tests/test_recipes.py
+++ b/tests/test_recipes.py
@@ -2,11 +2,12 @@ from decimal import Decimal
 from doctest import DocTestSuite
 from fractions import Fraction
 from functools import reduce
-from itertools import combinations, count, permutations
+from itertools import combinations, count, groupby, permutations
 from operator import mul
 from math import factorial
 from sys import version_info
 from unittest import TestCase, skipIf
+from unittest.mock import patch
 
 import more_itertools as mi
 
@@ -158,6 +159,22 @@ class AllEqualTests(TestCase):
         self.assertTrue(mi.all_equal('4٤໔４৪', key=int))
         self.assertFalse(mi.all_equal('Abc', key=str.casefold))
 
+    @patch('more_itertools.recipes.groupby', autospec=True)
+    def test_groupby_calls(self, mock_groupby):
+        next_count = 0
+
+        class _groupby(groupby):
+            def __next__(true_self):
+                nonlocal next_count
+                next_count += 1
+                return super().__next__()
+
+        mock_groupby.side_effect = _groupby
+        iterable = iter('aaaaa')
+        self.assertTrue(mi.all_equal(iterable))
+        self.assertEqual(list(iterable), [])
+        self.assertEqual(next_count, 2)
+
 
 class QuantifyTests(TestCase):
     """Tests for ``quantify()``"""