الفرق بين المراجعتين ل"Kotlin/collections/sortedWith"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الدالة <code>sortedWith()‎</code> في لغة Kotlin}}</noinclude> تعيد الدالة<code>sortedWith()‎</code> Kotlin/Array|م...')
 
ط
 
(3 مراجعات متوسطة بواسطة 3 مستخدمين غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: الدالة <code>sortedWith()‎</code> في لغة Kotlin}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الدالة <code>sortedWith()‎</code> في Kotlin}}</noinclude>
تعيد الدالة<code>sortedWith()‎</code> [[Kotlin/Array|مصفوفة]] تضم عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت عبرها مرتبة وفق المُقارِن المُمرّر <code>comparator</code>.  
+
ترتِّب الدالة <code>sortedWith()‎</code> جميع عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في قائمة.  
 
 
 
==البنية العامة==
 
==البنية العامة==
<nowiki/><nowiki/><syntaxhighlight lang="kotlin">
+
<syntaxhighlight lang="kotlin">
fun <T> Array<out T>.sortedArrayWith(
+
fun <T> Array<out T>.sortedWith(
 +
    comparator: Comparator<in T>
 +
): List<T>
 +
fun ByteArray.sortedWith(
 +
    comparator: Comparator<in Byte>
 +
): List<Byte>
 +
fun ShortArray.sortedWith(
 +
    comparator: Comparator<in Short>
 +
): List<Short>
 +
fun IntArray.sortedWith(
 +
    comparator: Comparator<in Int>
 +
): List<Int>
 +
fun LongArray.sortedWith(
 +
    comparator: Comparator<in Long>
 +
): List<Long>
 +
fun FloatArray.sortedWith(
 +
    comparator: Comparator<in Float>
 +
): List<Float>
 +
fun DoubleArray.sortedWith(
 +
    comparator: Comparator<in Double>
 +
): List<Double>
 +
fun BooleanArray.sortedWith(
 +
    comparator: Comparator<in Boolean>
 +
): List<Boolean>
 +
fun CharArray.sortedWith(
 +
    comparator: Comparator<in Char>
 +
): List<Char>
 +
fun <T> Iterable<T>.sortedWith(
 
     comparator: Comparator<in T>
 
     comparator: Comparator<in T>
): Array<out T>  
+
): List<T>  
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== القيمة المُعادة ==
+
== المعاملات ==
[[Kotlin/Array|مصفوفة]] تضم عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت عبرها مرتبة وفق المُقارِن المُمرّر <code>comparator</code>.
+
 
 +
=== <code>comparator</code> ===
 +
[[Kotlin/Comparator|المقارن]] الذي سترتَّب العناصر وفقًا له.
  
 +
==القيمة المعادة==
 +
تُعاد [[Kotlin/List|قائمة]] تضم جميع عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] المعطاة بعد ترتيبها وفقًا للمُقارِن <code>comparator</code> المعطى.
 
==أمثلة==
 
==أمثلة==
===استخدام الدالة <code>()sortedWith</code> مع المصفوفات===
+
استعمال الدالة <code>()sortedWith</code> لترتيب عناصر مصفوفة وفقًا لناتج طرح قيمة العنصر اللاحق من قيمة العنصر السابق:<syntaxhighlight lang="kotlin">
تعرف الشيفرة الآتية  <nowiki/>[[Kotlin/Array|مصفوفة]] <nowiki/>باسم <code>array</code> مكونة من ستة عناصر باستخدام الدالة <code>()arrayOf‎</code>، ثم تستخدم الدالة<code>()sortedWith</code>  على <code>array</code> لترتيبه وفق المقارِن المُمرّر كوسيط وتضع [[Kotlin/Array|المصفوفة]] المعادة في المتغير <code>array2</code>، ثم تطبعه:<syntaxhighlight lang="kotlin">
+
fun main(args: Array<String>) {
import java.util.Arrays
+
    val array = arrayOf(1, 9, -3, 7, 5, 6)
  
fun main(args: Array<String>) {
+
    print(array.sortedWith(Comparator { a, b -> b - a })) // [9, 7, 6, 5, 1, -3]
val array = arrayOf(1, 9, -3, 7, 5, 6)
 
val array2 = array.sortedArrayWith(Comparator { a, b -> b - a })
 
   
 
print (Arrays.toString (array2 )) // [9, 7, 6, 5, 1, -3]
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
==أنظر أيضًا==
+
==انظر أيضًا==
*<code>[[Kotlin/collections/sortBy|sortBy()]]</code>‎ : تقوم بترتيب  [[Kotlin/Array|المصفوفة]] أو [[Kotlin/MutableList|اللائحة المتغيرة]] (<code>MutableList</code>) التي استُدعيت عبرها وفقًا للقيم التي تعيدها الدالة المُمرّرة . 
+
*الدالة <code>[[Kotlin/collections/sorted|sorted()]]</code>‎: جميع عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو المجموعة التكرارية التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في قائمة.
 
+
*الدالة <code>[[Kotlin/collections/sortedArray|sortedArray()‎]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في [[Kotlin/List|مصفوفة]] جديدة.
* <code>[[Kotlin/collections/sort|sort()]]</code>‎ : تقوم بترتيب <nowiki/>[[Kotlin/Array|المصفوفة]] أو اللائحة المتغيرة (<code>MutableList</code>) التي استُدعيت عبرها.
+
*الدالة <code>[[Kotlin/collections/sortedArrayDescending|sortedArrayDescending()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في [[Kotlin/List|مصفوفة]] جديدة.
* <code>[[Kotlin/collections/sorted|sorted()]]</code>‎ : تعيد لائحة تضم عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو المجموعة التكرارية التي استُدعيت عبرها مرتبة وفق الترتيب الطبيعي.
+
*الدالة <code>[[Kotlin/collections/sortedArrayWith|sortedArrayWith()‎]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في مصفوفة جديدة.  
* <code>[[Kotlin/collections/sortedBy|sortedBy()]]</code>‎ : تعيد [[Kotlin/List|لائحة]] تضم عناصر [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت عبرها مرتبة ترتيبًا طبيعيًا وفقًا للقيم التي تعيدها الدالة المُمرّرة <code>selector</code>. 
+
*الدالة <code>[[Kotlin/collections/sortedBy|sortedBy()]]</code>: عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو القائمة المتغيرة (MutableList) التي استُدعيت معها تصاعديًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر.
 
+
*الدالة <code>[[Kotlin/collections/sortedByDescending|sortedByDescending()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] (Iterable) التي استُدعيت معها تنازليًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر ثمَّ تضع الناتج في قائمة. 
 +
*الدالة <code>[[Kotlin/collections/sortedDescending|sortedDescending()‎]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في [[Kotlin/List|قائمة]].
 +
* الدالة <code>[[Kotlin/collections/sortWith|sortWith()‎]]</code>: ترتِّب جميع عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو القائمة المتغيرة (MutableList) التي استُدعيت معها أو جزءًا محدَّدًا منها تنازليًا وفقًا للمُقارن المُمرّر إليها.  
 
==مصادر==
 
==مصادر==
*[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sorted-array-with.html الدالة  sortedWith()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
*[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sorted-with.html صفحة الدالة sortedWith()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
[[تصنيف:Kotlin Functions]]
+
[[تصنيف:Kotlin Function]]
 +
[[تصنيف:Kotlin Collection]]

المراجعة الحالية بتاريخ 11:18، 8 سبتمبر 2018

ترتِّب الدالة sortedWith()‎ جميع عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في قائمة.

البنية العامة

fun <T> Array<out T>.sortedWith(
    comparator: Comparator<in T>
): List<T> 
fun ByteArray.sortedWith(
    comparator: Comparator<in Byte>
): List<Byte> 
fun ShortArray.sortedWith(
    comparator: Comparator<in Short>
): List<Short> 
fun IntArray.sortedWith(
    comparator: Comparator<in Int>
): List<Int> 
fun LongArray.sortedWith(
    comparator: Comparator<in Long>
): List<Long> 
fun FloatArray.sortedWith(
    comparator: Comparator<in Float>
): List<Float>
fun DoubleArray.sortedWith(
    comparator: Comparator<in Double>
): List<Double>
fun BooleanArray.sortedWith(
    comparator: Comparator<in Boolean>
): List<Boolean> 
fun CharArray.sortedWith(
    comparator: Comparator<in Char>
): List<Char> 
fun <T> Iterable<T>.sortedWith(
    comparator: Comparator<in T>
): List<T>

المعاملات

comparator

المقارن الذي سترتَّب العناصر وفقًا له.

القيمة المعادة

تُعاد قائمة تضم جميع عناصر المصفوفة أو المجموعة التكرارية المعطاة بعد ترتيبها وفقًا للمُقارِن comparator المعطى.

أمثلة

استعمال الدالة ()sortedWith لترتيب عناصر مصفوفة وفقًا لناتج طرح قيمة العنصر اللاحق من قيمة العنصر السابق:

fun main(args: Array<String>) {
    val array = arrayOf(1, 9, -3, 7, 5, 6)

    print(array.sortedWith(Comparator { a, b -> b - a })) // [9, 7, 6, 5, 1, -3]
}

انظر أيضًا

  • الدالة sorted()‎: جميع عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في قائمة.
  • الدالة sortedArray()‎: ترتِّب جميع عناصر المصفوفة التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في مصفوفة جديدة.
  • الدالة sortedArrayDescending()‎: ترتِّب جميع عناصر المصفوفة التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في مصفوفة جديدة.
  • الدالة sortedArrayWith()‎: ترتِّب جميع عناصر المصفوفة التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في مصفوفة جديدة.  
  • الدالة sortedBy()‎: عناصر المصفوفة أو القائمة المتغيرة (MutableList) التي استُدعيت معها تصاعديًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر.
  • الدالة sortedByDescending()‎: ترتِّب جميع عناصر المصفوفة أو المجموعة التكرارية (Iterable) التي استُدعيت معها تنازليًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر ثمَّ تضع الناتج في قائمة. 
  • الدالة sortedDescending()‎: ترتِّب جميع عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في قائمة.
  • الدالة sortWith()‎: ترتِّب جميع عناصر المصفوفة أو القائمة المتغيرة (MutableList) التي استُدعيت معها أو جزءًا محدَّدًا منها تنازليًا وفقًا للمُقارن المُمرّر إليها.  

مصادر