Skip to content

Commit

Permalink
API: Implicits to automatically enable split macro syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
raquo committed Nov 23, 2024
1 parent 15aa447 commit 5681a58
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
3 changes: 0 additions & 3 deletions src/main/scala-2.12/scala/annotation/unused.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.raquo.airstream.core

trait ObservableMacroImplicits {
// Airstream's macro features are not implemented for Scala 2.
// See same-named file in `scala-3` directory.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.raquo.airstream.core

import com.raquo.airstream.core.{Observable, BaseObservable, Signal}
import com.raquo.airstream.split.{DuplicateKeysConfig, SplitMatchOneObservable, SplitMatchSeqObservable}

trait ObservableMacroImplicits {

extension [Self[+_] <: Observable[_], I](inline observable: BaseObservable[Self, I]) {
inline def splitMatchOne: SplitMatchOneObservable[Self, I, Nothing] =
SplitMatchOneObservable.build(observable)()()
}

extension [Self[+_] <: Observable[_], I, K, CC[_]](inline observable: BaseObservable[Self, CC[I]]) {
inline def splitMatchSeq(
inline keyFn: Function1[I, K],
inline distinctCompose: Function1[Signal[I], Signal[I]] = (iSignal: Signal[I]) => iSignal.distinct,
inline duplicateKeysConfig: DuplicateKeysConfig = DuplicateKeysConfig.default,
) = {
SplitMatchSeqObservable.build(keyFn, distinctCompose, duplicateKeysConfig, observable)()()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.raquo.airstream.split

import com.raquo.airstream.core.{
EventStream,
Signal,
Observable,
BaseObservable
}
import com.raquo.airstream.core.{EventStream, Signal, Observable, BaseObservable}
import scala.quoted.{Expr, Quotes, Type}
import scala.annotation.{unused, targetName}
import scala.compiletime.summonInline
Expand Down Expand Up @@ -57,11 +52,6 @@ import scala.reflect.TypeTest
*/
object SplitMatchOneMacros {

extension [Self[+_] <: Observable[_], I](inline observable: BaseObservable[Self, I]) {
inline def splitMatchOne: SplitMatchOneObservable[Self, I, Nothing] =
SplitMatchOneObservable.build(observable)()()
}

extension [Self[+_] <: Observable[_], I, O](
inline matchSplitObservable: SplitMatchOneObservable[Self, I, O]
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ import com.raquo.airstream.split.MacrosUtilities.{CaseAny, HandlerAny, MatchType

object SplitMatchSeqMacros {

extension [Self[+_] <: Observable[_], I, K, CC[_]](inline observable: BaseObservable[Self, CC[I]]) {
inline def splitMatchSeq(
inline keyFn: Function1[I, K],
inline distinctCompose: Function1[Signal[I], Signal[I]] = (iSignal: Signal[I]) => iSignal.distinct,
inline duplicateKeysConfig: DuplicateKeysConfig = DuplicateKeysConfig.default,
) = {
SplitMatchSeqObservable.build(keyFn, distinctCompose, duplicateKeysConfig, observable)()()
}
}

extension [Self[+_] <: Observable[_], I, K, O, CC[_]](
inline matchSplitObservable: SplitMatchSeqObservable[Self, I, K, O, CC]
) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/com/raquo/airstream/core/Observable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import scala.util.Try
*/
trait Observable[+A] extends BaseObservable[Observable, A] {}

object Observable extends ObservableLowPriorityImplicits {
object Observable
extends ObservableMacroImplicits
with ObservableLowPriorityImplicits {

/** Provides debug* methods on Observable: debugSpy, debugLogEvents, debugBreakErrors, etc. */
implicit def toDebuggableObservable[A](observable: Observable[A]): DebuggableObservable[Observable, A] = new DebuggableObservable[Observable, A](observable)
Expand Down

0 comments on commit 5681a58

Please sign in to comment.