Repository: passsy/kt.dart (dart)

Issue:
shuffled()
Add https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/shuffled.html

```kotlin
// Returns a new list with the elements of this list randomly shuffled.
fun <T> Iterable<T>.shuffled(): List<T>
```

Pull request description:
Closes #145 by adding shuffled() method to `KtIterable`

Patch:
diff --git a/lib/src/collection/kt_iterable.dart b/lib/src/collection/kt_iterable.dart
index 196af23..c6dae32 100644
--- a/lib/src/collection/kt_iterable.dart
+++ b/lib/src/collection/kt_iterable.dart
@@ -1110,6 +1110,11 @@ extension KtIterableExtensions<T> on KtIterable<T> {
     return list;
   }
 
+  /// Returns a new list with the elements of this list randomly shuffled.
+  KtList<T> shuffled([math.Random? random]) {
+    return toMutableList()..shuffle(random);
+  }
+
   /// Returns the single element matching the given [predicate], or throws an exception if the list is empty or has more than one element.
   T single([bool Function(T)? predicate]) {
     if (predicate == null) {


Test patch:
diff --git a/test/collection/iterable_extensions_test.dart b/test/collection/iterable_extensions_test.dart
index a8048cc..f394e1c 100644
--- a/test/collection/iterable_extensions_test.dart
+++ b/test/collection/iterable_extensions_test.dart
@@ -1,3 +1,5 @@
+import 'dart:math' as math;
+
 import "package:kt_dart/collection.dart";
 import "package:kt_dart/src/collection/impl/iterable.dart";
 import "package:test/test.dart";
@@ -1653,6 +1655,27 @@ void testIterable(KtIterable<T> Function<T>() emptyIterable,
     });
   });
 
+  group("shuffled", () {
+    test(
+        "shuffled returns a new list with shuffled items in the list with provided Random object",
+        () {
+      final list = iterableOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
+      final firstList = list.shuffled(math.Random(1));
+      expect(firstList, listOf(6, 4, 10, 9, 3, 2, 7, 8, 1, 5));
+
+      final secondList = list.shuffled(math.Random(2));
+      expect(secondList, listOf(8, 6, 3, 10, 9, 1, 2, 5, 7, 4));
+    });
+
+    test("empty", () {
+      expect(emptyIterable<int>().shuffled(), emptyList<int>());
+    });
+
+    test("one", () {
+      expect(listOf(1).shuffled(), listOf(1));
+    });
+  });
+
   group("single", () {
     test("single", () {
       expect(iterableOf([1]).single(), 1);