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

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

مراجعة 19:14، 22 يونيو 2018

تعيد الدالةsubtract()‎ مجموعة (Set) تضم عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت عبرها والتي لا توجد في المجموعة المُمرّرة.

المجموعة (Set) المُعادة تحافظ على ترتيب التكرار الخاص بالمجموعة (collection) المُمررة.

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

يمكن استدعاء الدالةsubtract()‎ عبر المصفوفات:

infix fun <T> Array<out T>.subtract(
    other: Iterable<T>
): Set<T> 
infix fun ByteArray.subtract(
    other: Iterable<Byte>
): Set<Byte> 
infix fun ShortArray.subtract(
    other: Iterable<Short>
): Set<Short> 
infix fun IntArray.subtract(other: Iterable<Int>): Set<Int>
infix fun LongArray.subtract(
    other: Iterable<Long>
): Set<Long> 
infix fun FloatArray.subtract(
    other: Iterable<Float>
): Set<Float> 
infix fun DoubleArray.subtract(
    other: Iterable<Double>
): Set<Double> 
infix fun BooleanArray.subtract(
    other: Iterable<Boolean>
): Set<Boolean> 
infix fun CharArray.subtract(
    other: Iterable<Char>
): Set<Char>

يمكن استدعاء الدالةsubtract()‎ عبر المجموعات التكرارية :

infix fun <T> Iterable<T>.subtract(
    other: Iterable<T>
): Set<T>

يُلاحَظ وجود الكلمة المفتاحية inline للدلالة على أن هذه الدالة مباشرة، وللمزيد من التفاصيل راجع توثيق الدوال المباشرة (inline functions).

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

مجموعة (Set) تضم عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت عبرها والتي لا توجد في المجموعة المُمرّرة.

أمثلة

استخدام الدالة ()subtract مع المصفوفات

تعرف الشيفرة الآتية  مصفوفة باسم array مكونة من ستة أعداد باستخدام الدالة ()arrayOf‎، ثم تعرّف  لائحة باسم list مكونة من ثلاثة أعداد باستخدام الدالة ()listOf، ثم تستخدم الدالة()subtract  على array بتمرير list كوسيط، ثم تطبع الناتج:

fun main(args: Array<String>) {
val array = arrayOf(3, 5, 7, 2 , 6, 9)
val list = listOf(3, 9, 1)
    
println(array.subtract(list))// [5, 7, 2, 6]
}

أنظر أيضًا

  • sort()‎ : تقوم بترتيب المصفوفة أو اللائحة المتغيرة (MutableList) التي استُدعيت عبرها.

مصادر