đ Kotlin Iterable āϏāĻšāĻāĻাāĻŦে āĻŦোāĻা!
đ Kotlin Iterable āϏāĻšāĻāĻাāĻŦে āĻŦোāĻা!
āϤুāĻŽি āĻি āĻāĻāύো āĻāĻāĻা āĻŦāĻā§েāϰ āĻĒৃāώ্āĻ া āĻāϞ্āĻে āĻĒā§েāĻো? đ āĻ িāĻ āϝেāĻŽāύ āĻāϰে āĻāĻŽāϰা āĻāĻāĻা āĻāĻāĻা āĻāϰে āĻĒৃāώ্āĻ া āĻāϞ্āĻাāĻ, Kotlin-āĻ Iterable āĻ িāĻ āĻāĻāĻāĻাāĻŦে āĻāĻāĻা āĻāĻāĻা āĻāϰে āĻĄেāĻা āĻĒā§āϤে āĻĻেā§!
đ¯ Iterable āĻŽাāύে āĻী?
đ Iterable āĻšāϞো Kotlin Collections-āĻāϰ Parent Interface, āϝা for āϞুāĻĒ āĻŦা Iterator āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰে āĻāĻāĻেāĻŽ āĻāĻāĻাāϰ āĻĒāϰ āĻāĻāĻা āĻĒā§āϤে āϏাāĻšাāϝ্āϝ āĻāϰে।
| đ āĻŽāύে āϰাāĻাāϰ āĻেāĻāĻā§ে | đ¤ āϏāĻšāĻ āĻŦ্āϝাāĻ্āϝা |
|---|---|
Iterable<T> |
āĻāĻি āĻāĻāĻা āĻāύ্āĻাāϰāĻĢেāϏ, āϝেāĻা āϏিāĻোā§েāύ্āϏ āĻ āύুāϝাā§ী āĻāϞিāĻŽেāύ্āĻ āĻ ্āϝাāĻ্āϏেāϏ āĻāϰāϤে āĻĻেā§। |
Iterator<T> |
āĻāĻি āĻāĻŽāύ āĻāĻāĻা āĻŽেāĻļিāύ, āϝেāĻা āĻāĻāĻা āĻāĻāĻা āĻāϰে āĻāϞিāĻŽেāύ্āĻ āĻĻেā§। |
forEach {} |
Iterable āĻĨেāĻে āĻāĻ āĻāĻ āĻāϰে āĻāĻāĻেāĻŽ āĻĒ্āϰāϏেāϏ āĻāϰāϤে āĻĻেā§। |
đ ️ 1. Iterable āĻিāĻাāĻŦে āĻাāĻ āĻāϰে?
val numbers: Iterable<Int> = listOf(10, 20, 30, 40)
// `for` āϞুāĻĒ āĻĻিā§ে āĻāĻāĻেāĻŽ āĻĒā§া
for (num in numbers) {
println(num)
}
// `forEach` āĻĢাংāĻļāύ āĻŦ্āϝāĻŦāĻšাāϰ
numbers.forEach { println(it) }
✅ āĻāĻাāύে numbers āĻāĻāĻা Iterable, āϤাāĻ āĻāĻŽāϰা for āϞুāĻĒ āĻŦা forEach āĻĻিā§ে āĻāĻ āĻāĻ āĻāϰে āĻāĻāĻেāĻŽ āύিāϤে āĻĒাāϰāĻি!
đ 2. Iterator āĻĻিā§ে āĻিāĻাāĻŦে Iterable āĻাāĻ āĻāϰে?
āϤুāĻŽি āϝāĻĻি āĻāĻāĻা āĻŦāĻā§েāϰ āĻĒৃāώ্āĻ া āĻāĻāĻাāϰ āĻĒāϰ āĻāĻāĻা āĻāϞ্āĻাāĻ, āϏেāĻা Iterator-āĻāϰ āĻŽāϤো āĻাāĻ āĻāϰāĻŦে!
val items = listOf("Apple", "Banana", "Mango")
val iterator = items.iterator() // Iterator āϤৈāϰি āĻāϰা
while (iterator.hasNext()) { // āϝāĻĻি āĻāĻāĻেāĻŽ āĻĨাāĻে
println(iterator.next()) // āĻĒāϰāĻŦāϰ্āϤী āĻāĻāĻেāĻŽ āύাāĻ
}
✅ āĻāĻাāύে hasNext() āĻেāĻ āĻāϰāĻে āĻোāύো āĻāĻāĻেāĻŽ āĻāĻে āĻিāύা, āĻāϰ next() āĻāĻāĻেāĻŽ āĻŦেāϰ āĻāϰāĻে।
đ 3. Iterable-āĻāϰ āĻিāĻু āĻĻāϰāĻাāϰি āĻĢাংāĻļāύ
| āĻĢাংāĻļāύ | āĻাāĻ | āĻāĻĻাāĻšāϰāĻŖ |
|---|---|---|
forEach {} |
āϏāĻŦ āĻāĻāĻেāĻŽ āĻāĻ āĻāĻ āĻāϰে āĻĒ্āϰāϏেāϏ āĻāϰে | list.forEach { println(it) } |
map {} |
āĻĒ্āϰāϤিāĻা āĻāϞিāĻŽেāύ্āĻ āĻĒ্āϰāϏেāϏ āĻāϰে āύāϤুāύ āϞিāϏ্āĻ āĻĻেā§ | list.map { it * 2 } |
filter {} |
āύিāϰ্āĻĻিāώ্āĻ āĻļāϰ্āϤে āĻŽিāϞ āĻĨাāĻা āĻāϞিāĻŽেāύ্āĻ āϰাāĻে | list.filter { it > 10 } |
first() |
āĻĒ্āϰāĻĨāĻŽ āĻāĻāĻেāĻŽ āϰিāĻাāϰ্āύ āĻāϰে | list.first() |
last() |
āĻļেāώ āĻāĻāĻেāĻŽ āϰিāĻাāϰ্āύ āĻāϰে | list.last() |
val numbers = listOf(5, 10, 15, 20)
// `map` āĻŦ্āϝāĻŦāĻšাāϰ
val doubled = numbers.map { it * 2 }
println(doubled) // Output: [10, 20, 30, 40]
// `filter` āĻŦ্āϝāĻŦāĻšাāϰ
val greaterThanTen = numbers.filter { it > 10 }
println(greaterThanTen) // Output: [15, 20]
đĨ 4. Iterable āĻŦāύাāĻŽ Sequence: āĻোāύāĻা āĻāĻāύ?
| Feature | Iterable | Sequence |
|---|---|---|
| Processing Type | āĻāĻāϏাāĻĨে āĻĒ্āϰāϏেāϏ āĻāϰে | āϧাāĻĒে āϧাāĻĒে āĻĒ্āϰāϏেāϏ āĻāϰে (Lazy) |
| Performance | āĻোāĻ āĻĄেāĻাāϰ āĻāύ্āϝ āĻĒাāϰāĻĢেāĻ্āĻ | āĻŦā§ āĻĄেāĻাāϰ āĻāύ্āϝ āĻাāϞো |
| Usage | āϏাāϧাāϰāĻŖ āϞিāϏ্āĻ āĻŦা āϏেāĻ | āϏ্āĻ্āϰিāĻŽিং āĻĄেāĻা |
val numbers = listOf(1, 2, 3, 4, 5) // Iterable
val seqNumbers = sequenceOf(1, 2, 3, 4, 5) // Sequence
đ āϏংāĻ্āώেāĻĒে āĻŽāύে āϰাāĻাāϰ āĻৌāĻļāϞ!
đ Iterable = āĻāĻāĻাāϰ āĻĒāϰ āĻāĻāĻা āĻāϞিāĻŽেāύ্āĻ āĻĒā§āϤে āĻĻেā§ (āϝেāĻŽāύ āĻŦāĻā§েāϰ āĻĒৃāώ্āĻ া)
đ Iterator = Iterable-āĻāϰ āĻāύ্āϝ āĻŽেāĻļিāύ, āϝা āĻāĻ āĻāĻ āĻāϰে āĻāĻāĻেāĻŽ āĻĻেā§
đ forEach, map, filter = Iterable āĻĒ্āϰāϏেāϏিং-āĻāϰ āĻāύ্āϝ āĻĻāϰāĻাāϰি āĻুāϞāϏ
āĻāĻāύ āĻি Iterable āĻ্āϞিā§াāϰ? đđđĨ
Comments
Post a Comment