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

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

A82a37a81ebdd732cb60c33d868382fa?s=47 omjoonkim
April 23, 2018

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

in droind knights 2018

A82a37a81ebdd732cb60c33d868382fa?s=128

omjoonkim

April 23, 2018
Tweet

More Decks by omjoonkim

Other Decks in Programming

Transcript

  1. Speaker. What is the difference between List, Sequence, and Observable?

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

    6th ݭ౭ - ۨ੉פझ౟ উ٘۽੉٘ ѐߊ੗. - ো೤ زইܻ MashUp ױ੢. - ইఃఫ୛, FPী ҙब੉ ݆׮. - email : omjoonkim@gmail.com - gitHub : https://github.com/omjoonkim - facebook : https://www.facebook.com/zkxns38
  3. WHAT?

  4. WHAT? List Sequence Observable

  5. WHAT? Method Chaining?

  6. WHAT? Method chaining, also known as named parameter idiom, is

    a common syntax for invoking multiple method calls in object- oriented programming languages
  7. WHAT? ߈ജ ч੉ Objectੋ ݫࣗ٘ܳ োࣘ੸ਵ۽ ࢎਊೞৈ ೐۽Ӓې߁ ೞח ੌ߈੸ੋ

    ҳޙ.
  8. WHAT? (1..100) .map { listOf(it) } .flatten() .filter { it

    % 3 == 0 } .forEach { println(it) }
  9. WHAT? List Sequence Observable

  10. WHY?

  11. য۵… WHY?

  12. ߑߨ਷.. ▸ ҕधകಕ੉૑, Documents ▸ StackOverFlow and Google god ▸

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

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

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

  16. ੉۠ ௏ٜ٘ਸ.. 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) }
  17. ਗې ߄۔਷.. HOW? class MergingSequence<T1, T2, V> class SubSequence<T> class

    TakeSequence<T> class DropSequence<T> class DistinctSequence<T, K>
  18. ਗې ߄۔਷.. 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)
  19. ೞ૑݅.. HOW?

  20. рױೞѱ! 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) }
  21. ઱੄ ೡ੼ ▸ ௏٘ܳ ખ ؊ ӭՔೞѱ ࠁӝ ਤ೧ оदࢿ

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

  23. LIST੄ CHAINING਷.. LIST ݒ chain݃׮ ࢜۽਍ destination(ܻझ౟)ܳ ݅ ٜয chain੄

    ೙ਃೠ ۈ׮ೣࣻܳ प೯ೠٍ Ѿҗчਸ destinationী ׸ই ׮਺ chainীѱ ֈѹ઱ח ߑध.
  24. LIST੄ CHAINING਷.. LIST LIST .filter() .map() .flatMap() predicate() LIST LIST

    transform() transform() Source(1..100)
  25. (1..100) .map { listOf(it) } .flatten() .filter { it %

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

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

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

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

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

    mapTo( ArrayList<R>(collectionSizeOrDefault(10)), transform ) } MAP? LIST map { listOf(it) }
  31. 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
  32. 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
  33. 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
  34. ׮द جইоࢲ.. 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 }
  35. ࢤࢿ੗۽… 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 }
  36. 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 }
  37. (1..100) .map { listOf(it) } .flatten() .filter { it %

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

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

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

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

    List<T> { return filterTo(ArrayList(), predicate) }
  42. 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 }
  43. 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 }
  44. (1..100) .map { listOf(it) } .flatten() .filter { it %

    3 == 0 } .forEach { println(it) } ਋ܻо ࢓ಝࠅ ௏٘! LIST
  45. FOREACH? LIST fun <T> Iterable<T>.forEach(action: (T) -> Unit): Unit {

    for (element in this) action(element) }
  46. рױ! LIST fun <T> Iterable<T>.forEach(action: (T) -> Unit): Unit {

    for (element in this) action(element) }
  47. ੿ܻೞݶ! LIST ܻझ౟ী ׸ӟ ؘ੉ఠо ݆ਸ ҃਋ method chainingߑधਸ ॳחѪ਷

    दр੉ য়ې Ѧܾ ࣻ ੓׮. ژೠ ୭ઙ Ѿҗ઺ ౠ੿ чਸ ଺ਵ۰ ೡ ٸ
 ژೠ ݽٚ elementী ؀ೠ chain੉ ՘աঠ݅ ഛੋೡ ࣻ ੓׮.
  48. SEQUENCE

  49. SEQUENCE੄ CHAINING਷.. SEQUENCE п chain݃׮ ঌݏ਷ Sequenceܳ ࢜۽ ٜ݅য ղݴ

    Terminal Sequence methodо ഐ୹ غ঻ਸ ٸ chain੄ ୐ Sequence੄ iteratorࠗఠ ࣽର੸ਵ۽ п chainػ Sequence੄ iterator੄ hasNext(), next()о ࣻ೯غয ୭ઙ Ѿҗޛਸ ߈ജೞח ߑध
  50. 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…
  51. 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 }
  52. SEQUECNE੄ CHAINING਷.. SEQUENCE .filter() .map() .flatMap() FILTERSEQUENCE predicate() Source(1..100) TRANSFORMING

    SEQUENCE FLATTENING SEQUENCE transform() transform() iterator iterator iterator
  53. 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 о ഐ ୹ ؼ ٸ!
  54. ਋ܻо ࢓ಝࠅ ௏٘! SEQUENCE (1..100).asSequence() .map { listOf(it) } .flatten()

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

    .filter { it % 3 == 0 } .forEach { println(it) }
  56. ASSQUENCE? SEQUENCE public fun <T> Iterable<T>.asSequence(): Sequence<T> { return Sequence

    { this.iterator() } } Iterable to Sequence
  57. SEQUENCEܳ ࢤࢿೞח ׮ܲ ߑߨ SEQUENCE public fun <T : Any>

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

    generateSequence( seed: T?, nextFunction: (T) -> T? ): Sequence<T> = if (seed == null) EmptySequence else GeneratorSequence({ seed }, nextFunction)
  59. ਋ܻо ࢓ಝࠅ ௏٘! SEQUENCE (1..100).asSequence() .map { listOf(it) } .flatten()

    .filter { it % 3 == 0 } .forEach { println(it) }
  60. MAP SEQUENCE public fun <T, R> Sequence<T>.map(transform: (T) -> R):

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

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

    Sequence<R> { return TransformingSequence(this, transform) } (1..100).asSequence()
  63. 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 ) } }
  64. ߄۽ ੉੹ 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 ) } }
  65. ղࠗী 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 ) } }
  66. 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 ) } }
  67. ਋ܻо ࢓ಝࠅ ௏٘! SEQUENCE (1..100).asSequence() .map { listOf(it) } .flatten()

    .filter { it % 3 == 0 } .forEach { println(it) }
  68. FLATTEN SEQUENCE public fun <T> Sequence<Iterable<T>>.flatten(): Sequence<T> = flatten {

    it.iterator() }
  69. 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() }
  70. 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) }
  71. ইө੹੄… 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 ) } }
  72. 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 } } }
  73. 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() } }
  74. 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() } }
  75. ղࠗ ೣࣻ ࠗ࠙ 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 }
  76. ղࠗ ೣࣻ ࠗ࠙ 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 }
  77. ղࠗ ೣࣻ ࠗ࠙ 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 }
  78. ղࠗ ೣࣻ ࠗ࠙ 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 }
  79. ղࠗ ೣࣻ ࠗ࠙ 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 }
  80. ׮द 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() } }
  81. ਋ܻо ࢓ಝࠅ ௏٘! SEQUENCE (1..100).asSequence() .map { listOf(it) } .flatten()

    .filter { it % 3 == 0 } .forEach { println(it) }
  82. FILTER SEQUENCE fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T> {

    return FilteringSequence(this, true, predicate) }
  83. FILTER SEQUENCE fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T> {

    return FilteringSequence(this, true, predicate) }
  84. 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 } } }
  85. ࢤࢿ੗ ࠗ࠙ SEQUENCE class FilteringSequence<T>( private val sequence: Sequence<T>, private

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

    val sendWhen: Boolean = true, private val predicate: (T) -> Boolean ) : Sequence<T>
  87. 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 } }
  88. 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 } }
  89. 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 } }
  90. NEXTSTATE, NEXTITEM? SEQUENCE nextState : calkNext() ೣࣻܳ ా೧ ೧׼ iteratorо

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

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

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

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

    { val item = iterator.next() if (predicate(item) == sendWhen) { nextItem = item nextState = 1 return } } nextState = 0 }
  95. 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 } }
  96. 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 } }
  97. ਋ܻо ࢓ಝࠅ ௏٘! SEQUENCE (1..100).asSequence() .map { listOf(it) } .flatten()

    .filter { it % 3 == 0 } .forEach { println(it) }
  98. FOREACH SEQUENCE fun <T> Sequence<T>.forEach(action: (T) -> Unit): Unit {

    for (element in this) action(element) }
  99. ਋ܻо ࢓ಝࠅ ௏٘! SEQUENCE fun <T> Sequence<T>.forEach(action: (T) -> Unit):

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

    methodо ഐ୹ ؼ ٸ ೧׼ methodী ٮܲ Ѿҗ ч੉ ഐ୹غח lazy initializeߑध ੑפ׮. ٮۄࢲ ੘਷ ࢎ੉ૉܳ о૑Ҋ ੓ਸ ҃਋ listࠁ׮ ো࢑੉ ו۰૕ ࣻ ੓ਵա ୽࠙൤ ݆਷ ন੄ ࢎ੉ૉ ഑਷ find, firstэ਷ ౠ੿ чਸ ߈ജ߉Ҋ रਸ ٸীח ؊ ബҗ੸ੌ ࣻ ੓णפ׮.
  101. OBSERVABLE

  102. OBSERVABLE੄ CHAINING਷.. OBSERVABLE п chain݃׮ ঌݏ਷ Observable৬ ؀਽ೞח Observer,Disposeableਸ ٜ݅য

    subscribeػ ٍ, ই੉మ੉ ߊ೯غݶ ୐ߣ૩ chainࠗఠ ݃૑݄ө૑ пп੄ Obsever۽૒੉ ࣻ೯غয Ѿҗޛ੉ ߈ജغח ߑध
  103. 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)
  104. ޷ܻ ঌই ل ࢎ೦ٜ OBSERVABLE ObjectHelper : ೧׼ ё୓о Nullੋ૑

    ౸ױೞৈ Exceptionਸ thorw೧઱ח ৉ೡ੄ Helper RxJavaPlugins : RxJava Libraryীࢲ ݽٚ Streamী ؀ೞৈ ҕ ా੸ਵ۽ ୊ܻೞҊ र਷ ۽૒੉ ੓ਸٸ ࢎਊೞח Plugin ௥ೞѱ झఈೞѷणפ׮.
  105. ௏٘о ցޖ ӡযਃ.. OBSERVABLE IDE۽ ૒੽ э੉ ࠁѷणפ׮!

  106. ੿ܻೞݶ.. OBSERVABLE Observable੄ ই઱ ӝࠄ੸ੋ chainingߑध੉ যڌѱ ҳഅ غয੓ח૑݅ਸ ঌইࠄ

    Ѫ੉ӝ ٸޙী Hot stream, subject١ਸ पઁ۽ ࢎਊ೧ ࠁݴ ղࠗ ҳഅ ௏٘ܳ ੉೧೧ ࠁदחѦ ୶ୌ ೤פ׮ :)
  107. ҡଳওաਃ..?

  108. Q&A

  109. Thank You!