CallbackOption

japgolly.scalajs.react.callback.CallbackOption
See theCallbackOption companion object
final class CallbackOption[+A](val underlyingRepr: () => A) extends AnyVal

Callback that can short-circuit along the way when conditions you specify, aren't met.

Especially useful for event handlers such as key handlers, drag-and-drop handlers, etc, where you check a condition, perform an effect, check another condition, perform another effect, etc.

This is meant to be lightweight, and be immediately useful without the typical pain of imports, implicit conversions and extension methods then normally accompany monad transforms in Scala.

For a more generic (i.e. beyond Option) or comprehensive monad transformer use Cats or similar.

Attributes

Companion
object
Graph
Supertypes
class AnyVal
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

inline def &&[B](b: CallbackOption[B]): CallbackOption[Unit]
inline def *>[B](next: CallbackOption[B]): CallbackOption[B]

Alias for >>.

Alias for >>.

Where >> is often associated with Monads, *> is often associated with Applicatives.

Attributes

def <*[B](next: CallbackOption[B]): CallbackOption[A]

Sequence actions, discarding the value of the second argument.

Sequence actions, discarding the value of the second argument.

Attributes

inline def <<[B](prev: CallbackOption[B]): CallbackOption[A]

Sequence a callback to run before this, discarding any value produced by it.

Sequence a callback to run before this, discarding any value produced by it.

Attributes

def <<?[B](prev: Option[CallbackOption[B]]): CallbackOption[A]

Convenient version of << that accepts an Option

Convenient version of << that accepts an Option

Attributes

def >>[B](next: CallbackOption[B]): CallbackOption[B]

Sequence a callback to run after this, discarding any value produced by this.

Sequence a callback to run after this, discarding any value produced by this.

Attributes

inline def >>=[B](f: A => CallbackOption[B]): CallbackOption[B]

Alias for flatMap.

Alias for flatMap.

Attributes

def asCallback: CallbackTo[Option[A]]
def filter(condition: A => Boolean): CallbackOption[A]
inline def filterNot(inline condition: A => Boolean): CallbackOption[A]
def finallyRun[B](runFinally: CallbackOption[B]): CallbackOption[A]

Wraps this callback in a try-finally block and runs the given callback in the finally clause, after the current callback completes, be it in error or success.

Wraps this callback in a try-finally block and runs the given callback in the finally clause, after the current callback completes, be it in error or success.

Attributes

def flatMap[B](f: A => CallbackOption[B]): CallbackOption[B]
def flatMapCB[B](f: A => CallbackTo[B]): CallbackOption[B]
def flatMapOption[B](f: A => Option[B]): CallbackOption[B]
def getOrElse[AA >: A](default: => AA): CallbackTo[AA]
def handleError[AA >: A](f: Throwable => CallbackOption[AA]): CallbackOption[AA]
inline def map[B](f: A => B)(using ev: MapGuard[B]): CallbackOption[Out]
def orElse[AA >: A](tryNext: CallbackOption[AA]): CallbackOption[AA]
inline def toCallback: Callback
Extension method from CallbackOption
def unary_!: CallbackOption[Unit]
Extension method from CallbackOption
def unless(cond: Boolean): CallbackOption[A]

Conditional execution of this callback. Reverse of when.

Conditional execution of this callback. Reverse of when.

Value parameters

cond

The condition required to be false for this callback to execute.

Attributes

Returns

Some result of the callback executed, else None.

inline def unless_(cond: => Boolean): CallbackOption[Unit]

Conditional execution of this callback. Reverse of when_.

Conditional execution of this callback. Reverse of when_.

Value parameters

cond

The condition required to be false for this callback to execute.

Attributes

Returns

Some result of the callback executed, else None.

def void: CallbackOption[Unit]

Discard the value produced by this callback.

Discard the value produced by this callback.

Attributes

inline def voidExplicit[B](using inline ev: A <:< B): CallbackOption[Unit]

Discard the value produced by this callback.

Discard the value produced by this callback.

This method allows you to be explicit about the type you're discarding (which may change in future).

Attributes

def when(cond: Boolean): CallbackOption[A]

Conditional execution of this callback.

Conditional execution of this callback.

Value parameters

cond

The condition required to be true for this callback to execute.

Attributes

def when_(cond: => Boolean): CallbackOption[Unit]

Conditional execution of this callback.

Conditional execution of this callback.

Value parameters

cond

The condition required to be true for this callback to execute.

Attributes

inline def withFilter(inline condition: A => Boolean): CallbackOption[A]
def zip[B](cb: CallbackOption[B]): CallbackOption[(A, B)]
inline def |[AA >: A](inline tryNext: CallbackOption[AA]): CallbackOption[AA]

Alias for orElse.

Alias for orElse.

Attributes

inline def |>[B](f: A => B)(using ev: MapGuard[B]): CallbackOption[Out]

Alias for map.

Alias for map.

Attributes

inline def ||[B](b: CallbackOption[B]): CallbackOption[Unit]

Concrete fields

val underlyingRepr: () => A