Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What is the difference between List, Sequence, ...

omjoonkim
April 23, 2018

What is the difference between List, Sequence, and Observable?

in droind knights 2018

omjoonkim

April 23, 2018
Tweet

More Decks by omjoonkim

Other Decks in Programming

Transcript

  1. SPEAKER ࣗѐ ӣߧળ - ઱۽ উ٘۽੉٘ܳ ѐߊ - ࣗ೐౟ਝয ݃ীझ౟۽

    6th ݭ౭ - ۨ੉פझ౟ উ٘۽੉٘ ѐߊ੗. - ো೤ زইܻ MashUp ױ੢. - ইఃఫ୛, FPী ҙब੉ ݆׮. - email : [email protected] - gitHub : https://github.com/omjoonkim - facebook : https://www.facebook.com/zkxns38
  2. WHAT? Method chaining, also known as named parameter idiom, is

    a common syntax for invoking multiple method calls in object- oriented programming languages
  3. ߑߨ਷.. ▸ ҕधകಕ੉૑, Documents ▸ StackOverFlow and Google god ▸

    प೯ ࣽࢲ؀۽ ҳഅغয ੓ח ௏٘ өࠁӝ WHY?
  4. ߑߨ਷.. ▸ ҕधകಕ੉૑, Documents ▸ StackOverFlow and Google god ▸

    प೯ ࣽࢲ؀۽ ҳഅغয ੓ח ௏٘ өࠁӝ WHY?
  5. ੉੼? ▸ ղࠗ ҳഅਸ ࠆਵ۽ ॄ ੉ۿ + पઁ ҳഅ

    ੉೧о ೤୛ઉ ݺഛೞѱ ੉೧ о оӝ औ׮. ▸ ೧׼ API, Libraryܳ ѐߊೠ ࢎۈٜ੄ ࢸ҅ ੄ب, ӒܻҊ ௏٘झఋੌ ਸ ખ ؊ Ө੉ ੓ѱ ঌ ࣻ ੓׮. ▸ ௏٘ ੉೧۱੉ ֫ই૓׮. ▸ য়೑ ࣗझী ӝৈೡ ࣻ ੓ח ੄޷੓ח ୐ ߊ੗Ҵ! WHY?
  6. ੉۠ ௏ٜ٘ਸ.. HOW? (1..100) .map { listOf(it) } .flatten() .filter

    { it % 3 == 0 } .forEach { println(it) } (1..100).asSequence() .map { listOf(it) } .flatten() .filter { it % 3 == 0 } .forEach { println(it) } Observable.fromIterable(1..100) .map { it * 2 } .filter { it % 3 == 0 } .subscribe { println(it) }
  7. ਗې ߄۔਷.. HOW? class MergingSequence<T1, T2, V> class SubSequence<T> class

    TakeSequence<T> class DropSequence<T> class DistinctSequence<T, K>
  8. ਗې ߄۔਷.. HOW? list.groupBy { it.from } .filter { it.key

    == KEY } .values .flatMap { it } .map { it.data } .flatMap { it } .forEach { println(it) } topicId .compose<Long> { loadBeforeComment.withLatestFrom(it, BiFunction { _, t2 -> t2 }) } .throttleFirst(1000, TimeUnit.MILLISECONDS) .flatMapMaybe { chatRepository.loadBeforeChat(it).neverError() } .bindToLifeCycle() .subscribe(successLoadChats)
  9. рױೞѱ! HOW? (1..100) .map { listOf(it) } .flatten() .filter {

    it % 3 == 0 } .forEach { println(it) } (1..100).asSequence() .map { listOf(it) } .flatten() .filter { it % 3 == 0 } .forEach { println(it) } Observable.fromIterable(1..100) .map { it * 2 } .filter { it % 3 == 0 } .subscribe { println(it) }
  10. ઱੄ ೡ੼ ▸ ௏٘ܳ ખ ؊ ӭՔೞѱ ࠁӝ ਤ೧ оदࢿ

    ߂ class ഑਷ method খױ ী ࠢח ఃਕٜ٘ਸ ઁѢೞ৓णפ׮. ▸ ௏٘ܳ ખ ؊ ӭՔೞѱ ࠁӝ ਤ೧ ਬਊೞҊ ੄޷ ੓ח Docsܳ ࢏ઁೞ ৓णפ׮. ▸ ݅ড पઁ۽ ௏٘ܳ ࠁन׮ݶ Docsܳ ࠁݶ ഻ঁ ੉೧ ೞӝ ए਋प Ѣীਃ! ▸ Observableэ਷ ҃਋ח दр࢚੄ ੉ਬ۽ о੢ рױೠ ColdStream ੄ ৘ઁ ௏٘۽ ഛੋೡ ৘੿ੑפ׮. HOW?
  11. LIST੄ CHAINING਷.. LIST ݒ chain݃׮ ࢜۽਍ destination(ܻझ౟)ܳ ݅ ٜয chain੄

    ೙ਃೠ ۈ׮ೣࣻܳ प೯ೠٍ Ѿҗчਸ destinationী ׸ই ׮਺ chainীѱ ֈѹ઱ח ߑध.
  12. (1..100) .map { listOf(it) } .flatten() .filter { it %

    3 == 0 } .forEach { println(it) } ਋ܻо ࢓ಝࠅ ௏٘! LIST
  13. (1..100) .map { listOf(it) } .flatten() .filter { it %

    3 == 0 } .forEach { println(it) } ਋ܻо ࢓ಝࠅ ௏٘! LIST
  14. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } MAP? LIST
  15. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } MAP? LIST
  16. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } MAP? LIST map { listOf(it) }
  17. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } MAP? LIST map { listOf(it) }
  18. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } COLLECTIONSIZEORDEFAULT? LIST fun <T> Iterable<T>.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default
  19. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } ੜࠁݶ ITERABLEী ഛ੢ ೣࣻ.. LIST fun <T> Iterable<T>.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default Progression Collection No Size
  20. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } Ӓېࢲ ੉۠ ೣࣻо… LIST fun <T> Iterable<T>.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default
  21. ׮द جইоࢲ.. MAPTO? LIST fun <T, R, C : MutableCollection<in

    R>> Iterable<T>.mapTo( destination: C, transform: (T) -> R ): C { for (item in this) destination.add(transform(item)) return destination }
  22. ࢤࢿ੗۽… LIST fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapTo(

    destination: C, transform: (T) -> R ): C { for (item in this) destination.add(transform(item)) return destination }
  23. DESTINATIONী чਸ ֍যળ׮ LIST fun <T, R, C : MutableCollection<in

    R>> Iterable<T>.mapTo( destination: C, transform: (T) -> R ): C { for (item in this) destination.add(transform(item)) return destination }
  24. (1..100) .map { listOf(it) } .flatten() .filter { it %

    3 == 0 } .forEach { println(it) } ਋ܻо ࢓ಝࠅ ௏٘! LIST
  25. FLATTEN? LIST fun <T> Iterable<Iterable<T>>.flatten(): List<T> { val result =

    ArrayList<T>() for (element in this) { result.addAll(element) } return result }
  26. MATTO୊ۢ.. LIST fun <T> Iterable<Iterable<T>>.flatten(): List<T> { val result =

    ArrayList<T>() for (element in this) { result.addAll(element) } return result }
  27. (1..100) .map { listOf(it) } .flatten() .filter { it %

    3 == 0 } .forEach { println(it) } ਋ܻо ࢓ಝࠅ ௏٘! LIST
  28. FILTER? LIST fun <T> Iterable<T>.filter( predicate: (T) -> Boolean ):

    List<T> { return filterTo(ArrayList(), predicate) }
  29. FILTER TO? LIST fun <T> Iterable<T>.filter( predicate: (T) -> Boolean

    ): List<T> { return filterTo(ArrayList(), predicate) } fun <T, C : MutableCollection<in T>> Iterable<T>.filterTo( destination: C, predicate: (T) -> Boolean ): C { for (element in this) if (predicate(element)) destination.add(element) return destination }
  30. MATTO, FLATTEN੄ ࣻ೯ ߑधҗ э׮ LIST fun <T> Iterable<T>.filter( predicate:

    (T) -> Boolean ): List<T> { return filterTo(ArrayList(), predicate) } fun <T, C : MutableCollection<in T>> Iterable<T>.filterTo( destination: C, predicate: (T) -> Boolean ): C { for (element in this) if (predicate(element)) destination.add(element) return destination }
  31. (1..100) .map { listOf(it) } .flatten() .filter { it %

    3 == 0 } .forEach { println(it) } ਋ܻо ࢓ಝࠅ ௏٘! LIST
  32. ੿ܻೞݶ! LIST ܻझ౟ী ׸ӟ ؘ੉ఠо ݆ਸ ҃਋ method chainingߑधਸ ॳחѪ਷

    दр੉ য়ې Ѧܾ ࣻ ੓׮. ژೠ ୭ઙ Ѿҗ઺ ౠ੿ чਸ ଺ਵ۰ ೡ ٸ
 ژೠ ݽٚ elementী ؀ೠ chain੉ ՘աঠ݅ ഛੋೡ ࣻ ੓׮.
  33. SEQUENCE੄ CHAINING਷.. SEQUENCE п chain݃׮ ঌݏ਷ Sequenceܳ ࢜۽ ٜ݅য ղݴ

    Terminal Sequence methodо ഐ୹ غ঻ਸ ٸ chain੄ ୐ Sequence੄ iteratorࠗఠ ࣽର੸ਵ۽ п chainػ Sequence੄ iterator੄ hasNext(), next()о ࣻ೯غয ୭ઙ Ѿҗޛਸ ߈ജೞח ߑध
  34. TERMINAL SEQUENCE? INTERMEDIATE SEQUENCE? SEQUENCE Terminal Sequence method: return ч੉

    Sequence о ইצ Sequence੄ method Ex) toList(), find() , first() , etc… Intermediate Sequence method: return ч੉ Sequenceੋ Sequence੄ method Ex) map(), filter() , flatten() , etc…
  35. SEQUENCE੄ ҳࢿ SEQUENCE public interface Sequence<out T> { public operator

    fun iterator(): Iterator<T> } public interface Iterator<out T> { public operator fun next(): T public operator fun hasNext(): Boolean }
  36. SEQUECNE੄ CHAINING਷.. SEQUENCE .filter() .map() .flatMap() FILTERSEQUENCE predicate() Source(1..100) TRANSFORMING

    SEQUENCE FLATTENING SEQUENCE transform() transform() iterator iterator iterator
  37. OPERATOR KEYWORD SEQUENCE public interface Sequence<out T> { public operator

    fun iterator(): Iterator<T> } public interface Iterator<out T> { public operator fun next(): T public operator fun hasNext(): Boolean } for (element in this) Terminate Sequence method о ഐ ୹ ؼ ٸ!
  38. SEQUENCEܳ ࢤࢿೞח ׮ܲ ߑߨ SEQUENCE public fun <T : Any>

    generateSequence( seed: T?, nextFunction: (T) -> T? ): Sequence<T> = if (seed == null) EmptySequence else GeneratorSequence({ seed }, nextFunction)
  39. SEQUENCEܳ ࢤࢿೞח ׮ܲ ߑߨ SEQUENCE public fun <T : Any>

    generateSequence( seed: T?, nextFunction: (T) -> T? ): Sequence<T> = if (seed == null) EmptySequence else GeneratorSequence({ seed }, nextFunction)
  40. MAP SEQUENCE public fun <T, R> Sequence<T>.map(transform: (T) -> R):

    Sequence<R> { return TransformingSequence(this, transform) }
  41. MAP SEQUENCE public fun <T, R> Sequence<T>.map(transform: (T) -> R):

    Sequence<R> { return TransformingSequence(this, transform) }
  42. MAP SEQUENCE public fun <T, R> Sequence<T>.map(transform: (T) -> R):

    Sequence<R> { return TransformingSequence(this, transform) } (1..100).asSequence()
  43. TRANSFORMINGSEQUENCE SEQUENCE class TransformingSequence<T, R> constructor( private val sequence: Sequence<T>,

    private val transformer: (T) -> R ) : Sequence<R> { override fun iterator(): Iterator<R> = object : Iterator<R> { val iterator = sequence.iterator() override fun next(): R { return transformer(iterator.next()) } override fun hasNext(): Boolean { return iterator.hasNext() } } fun <E> flatten(iterator: (R) -> Iterator<E>): Sequence<E> { return FlatteningSequence<T, R, E>( sequence, transformer, iterator ) } }
  44. ߄۽ ੉੹ SEQUENCE SEQUENCE class TransformingSequence<T, R> constructor( private val

    sequence: Sequence<T>, private val transformer: (T) -> R ) : Sequence<R> { override fun iterator(): Iterator<R> = object : Iterator<R> { val iterator = sequence.iterator() override fun next(): R { return transformer(iterator.next()) } override fun hasNext(): Boolean { return iterator.hasNext() } } fun <E> flatten(iterator: (R) -> Iterator<E>): Sequence<E> { return FlatteningSequence<T, R, E>( sequence, transformer, iterator ) } }
  45. ղࠗী ITERATORਸ о૑Ҋ ੓׮ SEQUENCE class TransformingSequence<T, R> constructor( private

    val sequence: Sequence<T>, private val transformer: (T) -> R ) : Sequence<R> { override fun iterator(): Iterator<R> = object : Iterator<R> { val iterator = sequence.iterator() override fun next(): R { return transformer(iterator.next()) } override fun hasNext(): Boolean { return iterator.hasNext() } } fun <E> flatten(iterator: (R) -> Iterator<E>): Sequence<E> { return FlatteningSequence<T, R, E>( sequence, transformer, iterator ) } }
  46. TRANSFORMINGSEQUENCE੄ ITERATOR METHODী ҙৈ SEQUENCE class TransformingSequence<T, R> constructor( private

    val sequence: Sequence<T>, private val transformer: (T) -> R ) : Sequence<R> { override fun iterator(): Iterator<R> = object : Iterator<R> { val iterator = sequence.iterator() override fun next(): R { return transformer(iterator.next()) } override fun hasNext(): Boolean { return iterator.hasNext() } } fun <E> flatten(iterator: (R) -> Iterator<E>): Sequence<E> { return FlatteningSequence<T, R, E>( sequence, transformer, iterator ) } }
  47. FLATTEN SEQUENCE fun <T, R> Sequence<T>.flatten( iterator: (T) -> Iterator<R>

    ): Sequence<R> { if (this is TransformingSequence<*, *>) { return (this as TransformingSequence<*, T>).flatten(iterator) } return FlatteningSequence(this, { it }, iterator) } public fun <T> Sequence<Iterable<T>>.flatten(): Sequence<T> = flatten { it.iterator() }
  48. FLATTEN SEQUENCE fun <T, R> Sequence<T>.flatten( iterator: (T) -> Iterator<R>

    ): Sequence<R> { if (this is TransformingSequence<*, *>) { return (this as TransformingSequence<*, T>).flatten(iterator) } return FlatteningSequence(this, { it }, iterator) } public fun <T> Sequence<Iterable<T>>.flatten(): Sequence<T> = flatten { it.iterator() } (1..100).asSequence() .map { listOf(it) } .flatten() .filter { it % 3 == 0 } .forEach { println(it) }
  49. ইө੹੄… SEQUENCE class TransformingSequence<T, R> constructor( private val sequence: Sequence<T>,

    private val transformer: (T) -> R ) : Sequence<R> { override fun iterator(): Iterator<R> = object : Iterator<R> { val iterator = sequence.iterator() override fun next(): R { return transformer(iterator.next()) } override fun hasNext(): Boolean { return iterator.hasNext() } } fun <E> flatten(iterator: (R) -> Iterator<E>): Sequence<E> { return FlatteningSequence<T, R, E>( sequence, transformer, iterator ) } }
  50. FLATTENINGSEQUENCE… SEQUENCE internal class FlatteningSequence<T, R, E> constructor( private val

    sequence: Sequence<T>, private val transformer: (T) -> R, private val iterator: (R) -> Iterator<E> ) : Sequence<E> { override fun iterator(): Iterator<E> = object : Iterator<E> { val iterator = sequence.iterator() var itemIterator: Iterator<E>? = null override fun next(): E { if (!ensureItemIterator()) throw NoSuchElementException() return itemIterator!!.next() } override fun hasNext(): Boolean { return ensureItemIterator() } private fun ensureItemIterator(): Boolean { if (itemIterator?.hasNext() == false) itemIterator = null while (itemIterator == null) { if (!iterator.hasNext()) { return false } else { val element = iterator.next() val nextItemIterator = iterator(transformer(element)) if (nextItemIterator.hasNext()) { itemIterator = nextItemIterator return true } } } return true } } }
  51. ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<E> = object :

    Iterator<E> { val iterator = sequence.iterator() var itemIterator: Iterator<E>? = null override fun next(): E { if (!ensureItemIterator()) throw NoSuchElementException() return itemIterator!!.next() } override fun hasNext(): Boolean { return ensureItemIterator() } }
  52. ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<E> = object :

    Iterator<E> { val iterator = sequence.iterator() var itemIterator: Iterator<E>? = null override fun next(): E { if (!ensureItemIterator()) throw NoSuchElementException() return itemIterator!!.next() } override fun hasNext(): Boolean { return ensureItemIterator() } }
  53. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun ensureItemIterator(): Boolean { if

    (itemIterator?.hasNext() == false) itemIterator = null while (itemIterator == null) { if (!iterator.hasNext()) { return false } else { val element = iterator.next() val nextItemIterator = iterator(transformer(element)) if (nextItemIterator.hasNext()) { itemIterator = nextItemIterator return true } } } return true }
  54. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun ensureItemIterator(): Boolean { if

    (itemIterator?.hasNext() == false) itemIterator = null while (itemIterator == null) { if (!iterator.hasNext()) { return false } else { val element = iterator.next() val nextItemIterator = iterator(transformer(element)) if (nextItemIterator.hasNext()) { itemIterator = nextItemIterator return true } } } return true }
  55. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun ensureItemIterator(): Boolean { if

    (itemIterator?.hasNext() == false) itemIterator = null while (itemIterator == null) { if (!iterator.hasNext()) { return false } else { val element = iterator.next() val nextItemIterator = iterator(transformer(element)) if (nextItemIterator.hasNext()) { itemIterator = nextItemIterator return true } } } return true }
  56. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun ensureItemIterator(): Boolean { if

    (itemIterator?.hasNext() == false) itemIterator = null while (itemIterator == null) { if (!iterator.hasNext()) { return false } else { val element = iterator.next() val nextItemIterator = iterator(transformer(element)) if (nextItemIterator.hasNext()) { itemIterator = nextItemIterator return true } } } return true }
  57. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun ensureItemIterator(): Boolean { if

    (itemIterator?.hasNext() == false) itemIterator = null while (itemIterator == null) { if (!iterator.hasNext()) { return false } else { val element = iterator.next() val nextItemIterator = iterator(transformer(element)) if (nextItemIterator.hasNext()) { itemIterator = nextItemIterator return true } } } return true }
  58. ׮द ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<E> = object

    : Iterator<E> { val iterator = sequence.iterator() var itemIterator: Iterator<E>? = null override fun next(): E { if (!ensureItemIterator()) throw NoSuchElementException() return itemIterator!!.next() } override fun hasNext(): Boolean { return ensureItemIterator() } }
  59. FILTER SEQUENCE internal class FilteringSequence<T>(private val sequence: Sequence<T>, private val

    sendWhen: Boolean = true, private val predicate: (T) -> Boolean ) : Sequence<T> { override fun iterator(): Iterator<T> = object : Iterator<T> { val iterator = sequence.iterator() var nextState: Int = -1 // -1 for unknown, 0 for done, 1 for continue var nextItem: T? = null private fun calcNext() { while (iterator.hasNext()) { val item = iterator.next() if (predicate(item) == sendWhen) { nextItem = item nextState = 1 return } } nextState = 0 } override fun next(): T { if (nextState == -1) calcNext() if (nextState == 0) throw NoSuchElementException() val result = nextItem nextItem = null nextState = -1 @Suppress("UNCHECKED_CAST") return result as T } override fun hasNext(): Boolean { if (nextState == -1) calcNext() return nextState == 1 } } }
  60. ࢤࢿ੗ ࠗ࠙ SEQUENCE class FilteringSequence<T>( private val sequence: Sequence<T>, private

    val sendWhen: Boolean = true, private val predicate: (T) -> Boolean ) : Sequence<T>
  61. ࢤࢿ੗ ࠗ࠙ SEQUENCE class FilteringSequence<T>( private val sequence: Sequence<T>, private

    val sendWhen: Boolean = true, private val predicate: (T) -> Boolean ) : Sequence<T>
  62. ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<T> = object :

    Iterator<T> { val iterator = sequence.iterator() var nextState: Int = -1 // -1 for unknown, 0 for done, 1 for continue var nextItem: T? = null override fun next(): T { if (nextState == -1) calcNext() if (nextState == 0) throw NoSuchElementException() val result = nextItem nextItem = null nextState = -1 @Suppress("UNCHECKED_CAST") return result as T } override fun hasNext(): Boolean { if (nextState == -1) calcNext() return nextState == 1 } }
  63. ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<T> = object :

    Iterator<T> { val iterator = sequence.iterator() var nextState: Int = -1 // -1 for unknown, 0 for done, 1 for continue var nextItem: T? = null override fun next(): T { if (nextState == -1) calcNext() if (nextState == 0) throw NoSuchElementException() val result = nextItem nextItem = null nextState = -1 @Suppress("UNCHECKED_CAST") return result as T } override fun hasNext(): Boolean { if (nextState == -1) calcNext() return nextState == 1 } }
  64. ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<T> = object :

    Iterator<T> { val iterator = sequence.iterator() var nextState: Int = -1 // -1 for unknown, 0 for done, 1 for continue var nextItem: T? = null override fun next(): T { if (nextState == -1) calcNext() if (nextState == 0) throw NoSuchElementException() val result = nextItem nextItem = null nextState = -1 @Suppress("UNCHECKED_CAST") return result as T } override fun hasNext(): Boolean { if (nextState == -1) calcNext() return nextState == 1 } }
  65. NEXTSTATE, NEXTITEM? SEQUENCE nextState : calkNext() ೣࣻܳ ా೧ ೧׼ iteratorо

    unknown,done,continue઺ যڃ ࢚కੋ૑ܳ աఋմ׮. 
 (GenreateSequenceэ਷ ҃਋ initial unknown ۄח ࢚కч੉ ୶о੸ਵ۽ ઓ੤.) ex) GeneratorSequence, FilteringSequence, TakeWhileSequence nextItem : calkNext() ೣࣻܳ ా೧ ೧׼ iterator੄ ׮਺ Itemчਸ о૑ѱ غח ߸ࣻ. nextState, nextItem, calkNext()ח ࣁ౟۽ ઓ੤ೠ׮.
  66. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun calcNext() { while (iterator.hasNext())

    { val item = iterator.next() if (predicate(item) == sendWhen) { nextItem = item nextState = 1 return } } nextState = 0 }
  67. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun calcNext() { while (iterator.hasNext())

    { val item = iterator.next() if (predicate(item) == sendWhen) { nextItem = item nextState = 1 return } } nextState = 0 }
  68. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun calcNext() { while (iterator.hasNext())

    { val item = iterator.next() if (predicate(item) == sendWhen) { nextItem = item nextState = 1 return } } nextState = 0 }
  69. ղࠗ ೣࣻ ࠗ࠙ SEQUENCE private fun calcNext() { while (iterator.hasNext())

    { val item = iterator.next() if (predicate(item) == sendWhen) { nextItem = item nextState = 1 return } } nextState = 0 }
  70. ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<T> = object :

    Iterator<T> { override fun next(): T { if (nextState == -1) calcNext() if (nextState == 0) throw NoSuchElementException() val result = nextItem nextItem = null nextState = -1 @Suppress("UNCHECKED_CAST") return result as T } override fun hasNext(): Boolean { if (nextState == -1) calcNext() return nextState == 1 } }
  71. ITERATOR ࠗ࠙ SEQUENCE override fun iterator(): Iterator<T> = object :

    Iterator<T> { override fun next(): T { if (nextState == -1) calcNext() if (nextState == 0) throw NoSuchElementException() val result = nextItem nextItem = null nextState = -1 @Suppress("UNCHECKED_CAST") return result as T } override fun hasNext(): Boolean { if (nextState == -1) calcNext() return nextState == 1 } }
  72. ਋ܻо ࢓ಝࠅ ௏٘! SEQUENCE fun <T> Sequence<T>.forEach(action: (T) -> Unit):

    Unit { for (element in this) action(element) } Terminate Sequence method
  73. ੿ܻೞݶ! SEQUENCE Sequence੄ chaining਷ ૊п੸ਵ۽ ۽૒੉ ࣻ೯غח Ѫ੉ ইצ Terminate

    methodо ഐ୹ ؼ ٸ ೧׼ methodী ٮܲ Ѿҗ ч੉ ഐ୹غח lazy initializeߑध ੑפ׮. ٮۄࢲ ੘਷ ࢎ੉ૉܳ о૑Ҋ ੓ਸ ҃਋ listࠁ׮ ো࢑੉ ו۰૕ ࣻ ੓ਵա ୽࠙൤ ݆਷ ন੄ ࢎ੉ૉ ഑਷ find, firstэ਷ ౠ੿ чਸ ߈ജ߉Ҋ रਸ ٸীח ؊ ബҗ੸ੌ ࣻ ੓णפ׮.
  74. OBSERVABLE੄ CHAINING਷.. OBSERVABLE п chain݃׮ ঌݏ਷ Observable৬ ؀਽ೞח Observer,Disposeableਸ ٜ݅য

    subscribeػ ٍ, ই੉మ੉ ߊ೯غݶ ୐ߣ૩ chainࠗఠ ݃૑݄ө૑ пп੄ Obsever۽૒੉ ࣻ೯غয Ѿҗޛ੉ ߈ജغח ߑध
  75. OBSERVABLE .filter() .map() Source(1..100) .subscribe() LamdaObserver MapObserver actual = LamdaObserver

    FilterObserver actual = MapObserver observer.onSubscribe() source.subscribe(observer) source.subscribe(observer) observer.onNext() ખ ؊ ੗ࣁ൤.. ObservableMap.subscribeActual(observer) ObservableFilter.subscribeActual(observer) Source.subscribeActual(observer)
  76. ޷ܻ ঌই ل ࢎ೦ٜ OBSERVABLE ObjectHelper : ೧׼ ё୓о Nullੋ૑

    ౸ױೞৈ Exceptionਸ thorw೧઱ח ৉ೡ੄ Helper RxJavaPlugins : RxJava Libraryীࢲ ݽٚ Streamী ؀ೞৈ ҕ ా੸ਵ۽ ୊ܻೞҊ र਷ ۽૒੉ ੓ਸٸ ࢎਊೞח Plugin ௥ೞѱ झఈೞѷणפ׮.
  77. ੿ܻೞݶ.. OBSERVABLE Observable੄ ই઱ ӝࠄ੸ੋ chainingߑध੉ যڌѱ ҳഅ غয੓ח૑݅ਸ ঌইࠄ

    Ѫ੉ӝ ٸޙী Hot stream, subject١ਸ पઁ۽ ࢎਊ೧ ࠁݴ ղࠗ ҳഅ ௏٘ܳ ੉೧೧ ࠁदחѦ ୶ୌ ೤פ׮ :)
  78. Q&A