You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.5 KiB

  1. package nova.monadic_sfx.util.controls
  2. import monix.execution.Cancelable
  3. import monix.execution.Scheduler
  4. import monix.execution.cancelables.CompositeCancelable
  5. import monix.reactive.Observable
  6. import monix.reactive.Observer
  7. import monix.{eval => me}
  8. import nova.monadic_sfx.util.reactive.store.Sink2
  9. import nova.monadic_sfx.implicits._
  10. object ActionObservableDsl {
  11. implicit final class ActionObservableExecutor[T](
  12. private val delegate: Observable[T]
  13. ) {
  14. // def -->[G](sub: G)(implicit s: Scheduler, G: Sink[G, T]) =
  15. // // delegate
  16. // // .doOnNext(el => me.Task.deferFuture(sub.onNext(el)) >> me.Task.unit)
  17. // // .subscribe()
  18. // delegate
  19. // .doOnNext(el => G.offer(sub, el))
  20. // .subscribe()
  21. def -->(
  22. sink: Sink2[T]
  23. )(implicit s: Scheduler, c: CompositeCancelable) =
  24. // delegate
  25. // .doOnNext(el => me.Task.deferFuture(sub.onNext(el)) >> me.Task.unit)
  26. // .subscribe()
  27. c += delegate
  28. .doOnNext(el => sink.offer(el).toTask)
  29. .subscribe()
  30. }
  31. }
  32. // final class ActionObservableBuilder[A](
  33. // private val observableAction: Observable[A]
  34. // ) extends AnyVal {
  35. // def useLazyEval[T](v: me.Task[T]) =
  36. // new ActionObservableExecutor[T](observableAction.mapEval(_ => v))
  37. // def useEval[T](cb: A => me.Task[T]) =
  38. // new ActionObservableExecutor[T](
  39. // observableAction.mapEval(cb)
  40. // )
  41. // def useIterableEval[T](cb: A => collection.immutable.Iterable[T]) =
  42. // new ActionObservableExecutor[T](
  43. // observableAction.flatMap(a =>
  44. // Observable.suspend(Observable.fromIterable(cb(a)))
  45. // )
  46. // )
  47. // def use = new ActionObservableExecutor(observableAction)
  48. // def doOnNext(cb: A => me.Task[Unit]): ActionObservableBuilder[A] =
  49. // new ActionObservableBuilder(observableAction.doOnNext(cb))
  50. // def mapEval[B](cb: A => me.Task[B]) =
  51. // new ActionObservableBuilder(observableAction.mapEval(cb))
  52. // def underlying = observableAction
  53. // // Caution: Experimental stuff below..
  54. // def useEval2[B, C](f: A => me.Task[B], g: A => me.Task[C]) =
  55. // new ActionObservableExecutor[(B, C)](
  56. // observableAction.publishSelector(conn =>
  57. // conn
  58. // .mapEval(f)
  59. // .switchMap(b =>
  60. // conn.mapEval(a =>
  61. // for {
  62. // c <- g(a)
  63. // } yield (b, c)
  64. // )
  65. // )
  66. // )
  67. // )
  68. // // def bifurcate[B, C](
  69. // // f: ActionObservableBuilder[A] => B,
  70. // // g: ActionObservableBuilder[A] => C
  71. // // )(implicit s: Scheduler) =
  72. // // observableAction
  73. // // .publishSelector(conn =>
  74. // // Observable(
  75. // // Observable.unit.doOnNext(_ =>
  76. // // me.Task(f(new ActionObservableBuilder[A](conn))) >> me.Task.unit
  77. // // ),
  78. // // Observable.unit.doOnNext(_ =>
  79. // // me.Task(g(new ActionObservableBuilder[A](conn))) >> me.Task.unit
  80. // // )
  81. // // ).merge
  82. // // )
  83. // // .subscribe()
  84. // def split(
  85. // lst: (ActionObservableBuilder[A] => Cancelable)*
  86. // )(implicit s: Scheduler): Cancelable = {
  87. // val cc = CompositeCancelable()
  88. // cc += observableAction
  89. // .publishSelector(conn =>
  90. // Observable(
  91. // lst.map(f =>
  92. // Observable.unit.doOnNext(_ =>
  93. // me.Task(
  94. // cc += f(new ActionObservableBuilder[A](conn))
  95. // ) >> me.Task.unit
  96. // )
  97. // ): _*
  98. // ).merge
  99. // )
  100. // .subscribe()
  101. // }
  102. // }