object Box extends BoxTrait with Tryo with Serializable
The Box companion object provides methods to create a Box from:
- an
Option
- a
List
- any
AnyRef
object, convertingnull
toEmpty
and anything else to aFull
with the given object
It also provides implicit methods to transform Option
to Box
, Box
to
Iterable
, and Box
to Option
.
- Alphabetic
- By Inheritance
- Box
- Serializable
- Serializable
- Tryo
- BoxTrait
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
implicit final
class
ListOfBoxes
[T] extends AnyVal
Helper class to provide an easy way for converting a
List[Box[T]]
into aBox[List[T]]
.
Value Members
-
def
!![T](in: T): Box[T]
Alias for
legacyNullTest
.Alias for
legacyNullTest
.- Definition Classes
- BoxTrait
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
apply[InType, OutType](value: InType)(pf: PartialFunction[InType, OutType]): Box[OutType]
Apply the specified
PartialFunction
to the specifiedvalue
and return the result in aFull
; if thepf
is not defined at that point return
Empty
.Apply the specified
PartialFunction
to the specifiedvalue
and return the result in aFull
; if thepf
is not defined at that point return
Empty
.- value
The value to transform.
- pf
The partial function to use to transform the value.
- returns
A
Full
containing the transformed value ifpf.isDefinedAt(value)
andEmpty
otherwise.
- Definition Classes
- BoxTrait
-
def
apply[InType, OutType](pf: PartialFunction[InType, OutType])(value: InType): Box[OutType]
Apply the specified
PartialFunction
to the specifiedvalue
and return the result in aFull
; if thepf
is not defined at that point return
Empty.
Apply the specified
PartialFunction
to the specifiedvalue
and return the result in aFull
; if thepf
is not defined at that point return
Empty.
- pf
The partial function to use to transform the value.
- value
The value to transform.
- returns
A
Full
containing the transformed value ifpf.isDefinedAt(value)
andEmpty
otherwise.
- Definition Classes
- BoxTrait
-
def
apply[T](in: List[T]): Box[T]
Transform a
List
with zero or more elements to aBox
, losing all but the first element if there are more than one.Transform a
List
with zero or more elements to aBox
, losing all but the first element if there are more than one.- returns
Full(x)
with the head of the list if it contains at least one element andEmpty
otherwise.
- Definition Classes
- BoxTrait
-
def
apply[T](in: Box[T]): Box[T]
Create a
Box
from the specifiedBox
, checking fornull
.Create a
Box
from the specifiedBox
, checking fornull
.- returns
Full(in)
ifin
is aFull
box and its value is non-null,Empty
otherwise.
- Definition Classes
- BoxTrait
-
def
apply[T](in: Option[T]): Box[T]
Create a
Box
from the specifiedOption
.Create a
Box
from the specifiedOption
.- returns
Full
with the contents if theOption
isSome
andEmpty
otherwise.
- Definition Classes
- BoxTrait
-
def
asA[B](in: T forSome {type T})(implicit m: Manifest[B]): Box[B]
Create a
Full
box containing the specified value ifin
is of typeB
andEmpty
otherwise.Create a
Full
box containing the specified value ifin
is of typeB
andEmpty
otherwise.For example:
scala> Box.asA[Int]("boom") res0: net.liftweb.common.Box[Int] = Empty scala> Box.asA[Int](5) res1: net.liftweb.common.Box[Int] = Full(5)
- Definition Classes
- BoxTrait
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
implicit
def
box2Iterable[T](in: Box[T]): Iterable[T]
This implicit transformation allows one to use a
Box
as anIterable
of zero or one elements. -
implicit
def
box2Option[T](in: Box[T]): Option[T]
This implicit transformation allows one to use a
Box
as anOption
.This implicit transformation allows one to use a
Box
as anOption
.Note that
Box
implementsget
specifically to avoid usage of.get
onBox
instances. Boxes should be opened usingopenOrThrowException
and their contents compared using== Full(expectedValue)
.- returns
Some
with the contents if the box isFull
andNone
otherwise.
- Definition Classes
- BoxTrait
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
def
isA[A, B](in: A, clz: Class[B]): Box[B]
Create a
Full
box containing the specified value ifin
is an instance of the specified classclz
andEmpty
otherwise.Create a
Full
box containing the specified value ifin
is an instance of the specified classclz
andEmpty
otherwise.This is basically a Java-friendly version of
asA
, which you should prefer when using Scala.For example:
scala> Box.isA("boom", classOf[Int]) res0: net.liftweb.common.Box[Int] = Empty scala> Box.isA(5, classOf[Int]) res1: net.liftweb.common.Box[Int] = Full(5)
- Definition Classes
- BoxTrait
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
legacyNullTest[T](in: T): Box[T]
This method allows one to encapsulate any object in a Box in a null-safe manner, converting
null
values toEmpty
.This method allows one to encapsulate any object in a Box in a null-safe manner, converting
null
values toEmpty
.- returns
Full
ifin
is not null andEmpty
otherwise.
- Definition Classes
- BoxTrait
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
implicit
def
option2Box[T](in: Option[T]): Box[T]
This implicit transformation allows one to use an
Option
as aBox
.This implicit transformation allows one to use an
Option
as aBox
.- returns
Full
with the contents if theOption
isSome
andEmpty
otherwise.
- Definition Classes
- BoxTrait
-
val
primitiveMap: Map[Class[_], Class[_]]
- Definition Classes
- BoxTrait
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
tryo[T](ignore: Class[_])(f: ⇒ T): Box[T]
Wraps a "try" block around the function f.
Wraps a "try" block around the function f. Takes only one Class of exception to ignore
- ignore
- a single exception classes to ignore. A thrown exception will be ignored if it is assignable from this class.
- f
- the block of code to evaluate
- returns
- Full(result of the evaluation of f) if f doesn't throw any exception
- a Failure if f throws an exception
- Empty if the exception class is in the ignore list
- Definition Classes
- Tryo
-
def
tryo[T](ignore: List[Class[_]])(f: ⇒ T): Box[T]
Wraps a "try" block around the function f
Wraps a "try" block around the function f
- ignore
- a list of exception classes to ignore. A thrown exception will be ignored if it is assignable from one of the exception classes in the list
- f
- the block of code to evaluate
- returns
- Full(result of the evaluation of f) if f doesn't throw any exception
- a Failure if f throws an exception
- Empty if the exception class is in the ignore list
- Definition Classes
- Tryo
-
def
tryo[T](onError: (Throwable) ⇒ Unit)(f: ⇒ T): Box[T]
Wraps a "try" block around the function f and trigger a callback function if an exception is thrown
Wraps a "try" block around the function f and trigger a callback function if an exception is thrown
- onError
- an optional callback function that will use the thrown exception as a parameter
- f
- the block of code to evaluate
- returns
- Full(result of the evaluation of f) if f doesn't throw any exception
- a Failure if f throws an exception
- Definition Classes
- Tryo
-
def
tryo[T](f: ⇒ T): Box[T]
Wraps a "try" block around the function f
Wraps a "try" block around the function f
- f
- the block of code to evaluate
- returns
- Full(result of the evaluation of f) if f doesn't throw any exception
- a Failure if f throws an exception
- Definition Classes
- Tryo
-
def
tryo[T](handler: PartialFunction[Throwable, T], f: ⇒ T): Box[T]
Wraps a "try" block around the function f.
Wraps a "try" block around the function f. If f throws an exception that is in the domain of the handler PF, the handler will be invoked on the exception. Otherwise the exception is wrapped into a Failure.
- handler
- A partial function that handles exceptions
- f
- the block of code to evaluate
- returns
- Full(result of the evaluation of f) if f doesn't throw any exception
- a Failure if f throws an exception
- Definition Classes
- Tryo
- See also
net.liftweb.common.Failure
-
def
tryo[T](ignore: List[Class[_]], onError: Box[(Throwable) ⇒ Unit])(f: ⇒ T): Box[T]
Wraps a "try" block around the function f.
Wraps a "try" block around the function f. If f throws an exception with its class in the 'ignore' list or if 'ignore' is null or an empty list, ignore the exception and return None.
- ignore
- a list of exception classes to ignore. A thrown exception will be ignored if it is assignable from one of the exception classes in the list
- onError
- an optional callback function that will use the thrown exception as a parameter
- f
- the block of code to evaluate
- returns
- Full(result of the evaluation of f) if f doesn't throw any exception
- a Failure if f throws an exception
- Empty if the exception class is in the ignore list
- Definition Classes
- Tryo
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )