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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الدالة <code>subtract()‎</code> في لغة Kotlin}}</noinclude> تعيد الدالة<code>subtract()‎</code> Kotlin/List|لائ...')
 
ط
 
(4 مراجعات متوسطة بواسطة 3 مستخدمين غير معروضة)
سطر 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|المجموعة]] (Set) المُعادة على ترتيب التكرار الخاص [[Kotlin/collections|بالمجموعة]] (collection) المعطاة.
  
 
==البنية العامة==
 
==البنية العامة==
<nowiki/><nowiki/><syntaxhighlight lang="kotlin">
+
يمكن استدعاء الدالة <code>subtract()‎</code> مع [[Kotlin/Array|المصفوفات]] و<nowiki/>[[Kotlin/Iterable|المجموعات التكرارية]]:<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>  
+
infix fun <T> Iterable<T>.subtract(
fun <T> Iterable<T>.sortedWith(
+
     other: Iterable<T>
     comparator: Comparator<in T>
+
): Set<T>  
): List<T>  
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== القيمة المُعادة ==
+
== المعاملات ==
[[Kotlin/List|لائحة]] تضم عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت عبرها مرتبة وفق المُقارِن المُمرّر <code>comparator</code>.
+
 
 +
=== <code>other</code> ===
 +
الكائن الآخر الذي ستطبق عليه العملية.
 +
 
 +
== القيمة المعادة ==
 +
تُعاد [[Kotlin/Set|مجموعة]] (Set) تضم جميع العناصر الموجودة في [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] المعطاة والغير موجودة في المعامل <code>other</code> المعطى.
  
 
==أمثلة==
 
==أمثلة==
===استخدام الدالة <code>()subtract</code> مع المصفوفات===
+
<nowiki/><nowiki/><nowiki/>استعمال الدالة <code>()subtract</code> لاستثناء العناصر المشتركة بين كائنين:<syntaxhighlight lang="kotlin">
تعرف الشيفرة الآتية  <nowiki/>[[Kotlin/Array|مصفوفة]] <nowiki/>باسم <code>array</code> مكونة من ستة عناصر باستخدام الدالة <code>()arrayOf‎</code>، ثم تستخدم الدالة<code>()subtract</code>  على <code>array</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/union|union()]]</code>: تجمع العناصر المشتركة وغير المتشركة بين [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها وبين [[Kotlin/Iterable|المجموعة التكرارية]] المُمرّرة إليها في مجموعةٍ واحدةٍ من النوع <code>[[Kotlin/Set|Set]]</code> بعد حذف العناصر المتكررة.
 
+
* الدالة <code>[[Kotlin/collections/plusElement|plusElement()]]</code>: تضيف العنصر المُمرّر إليها إلى <nowiki/>[[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها.
* <code>[[Kotlin/collections/sort|sort()]]</code>‎ : تقوم بترتيب <nowiki/>[[Kotlin/Array|المصفوفة]] أو اللائحة المتغيرة (<code>MutableList</code>) التي استُدعيت عبرها.
+
* الدالة <code>[[Kotlin/collections/slice|slice()]]</code>‎ : تقطع جزءًا محدَّدًا من <nowiki/>[[Kotlin/Array|المصفوفة]] أو القائمة التي استُدعيت معها ثمَّ تعيده في قائمة.
* <code>[[Kotlin/collections/sorted|sorted()]]</code>‎ : تعيد لائحة تضم عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو المجموعة التكرارية التي استُدعيت عبرها مرتبة وفق الترتيب الطبيعي.
+
* الدالة <code>[[Kotlin/collections/sum|sum()]]</code>: تجمع جميع قيم عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/collections|المجموعة]] التي استُدعيت معها ثمَّ تعيد الناتج.
* <code>[[Kotlin/collections/sortedBy|sortedBy()]]</code>‎ : تعيد [[Kotlin/List|لائحة]] تضم عناصر [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت عبرها مرتبة ترتيبًا طبيعيًا وفقًا للقيم التي تعيدها الدالة المُمرّرة <code>selector</code>. 
+
* الدالة <code>[[Kotlin/collections/sort|sort()]]</code>‎ : ترتب <nowiki/>[[Kotlin/Array|المصفوفة]] أو القائمة المتغيرة (MutableList) التي استُدعيت معها تصاعديًّا.
  
 
==مصادر==
 
==مصادر==
*[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 Function]]
 +
[[تصنيف:Kotlin Collection]]

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

تستثني الدالة subtract()‎ العناصر المشتركة بين كائنين.

تحافظ المجموعة (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> 

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

المعاملات

other

الكائن الآخر الذي ستطبق عليه العملية.

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

تُعاد مجموعة (Set) تضم جميع العناصر الموجودة في المصفوفة أو المجموعة التكرارية المعطاة والغير موجودة في المعامل other المعطى.

أمثلة

استعمال الدالة ()subtract لاستثناء العناصر المشتركة بين كائنين:

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]
}

انظر أيضًا

مصادر