Skip to content

Commit

Permalink
Syntactic Sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
nob13 committed May 3, 2024
1 parent dbe3871 commit 8d2af5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/shared/src/main/scala/kreuzberg/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ final class Channel[T] private {
def trigger(value: T)(using h: HandlerContext): Unit = {
h.triggerChannel(this, value)
}

/** Trigger from Handler (Unit or Any) */
def trigger()(using h: HandlerContext, ev: Unit => T): Unit = {
h.triggerChannel(this, ev(()))
}
}

object Channel {
Expand Down
5 changes: 5 additions & 0 deletions lib/shared/src/main/scala/kreuzberg/EventBinding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ sealed trait EventSink[-E] {
def trigger(value: E)(using h: HandlerContext): Unit = {
h.triggerSink(this, value)
}

/** Like trigger, but for Unit and or Any */
def trigger()(using h: HandlerContext, ev: Unit => E): Unit = {
trigger(ev(()))
}
}

object EventSink {
Expand Down

0 comments on commit 8d2af5a

Please sign in to comment.