object Empty extends EmptyBox with Product with Serializable
Singleton object representing a completely empty Box
with no value or
failure information.
- Alphabetic
- By Inheritance
- Empty
- EmptyBox
- Box
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
class
WithFilter
extends AnyRef
Makes
Box
play better with Scalafor
comprehensions.Makes
Box
play better with Scalafor
comprehensions.- Definition Classes
- Box
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
$(f: (Box[Nothing]) ⇒ Unit): Box[Nothing]
Alias for
pass
. -
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
===[B >: Nothing](to: B): Boolean
Returns true if the value contained in this box is equal to the specified value.
Returns true if the value contained in this box is equal to the specified value. This is the same thing that
==
does when it's handed a value that isn't aBox
, but using this is recommended because it's clearer that the behavior will be different than the usual expectation.- Definition Classes
- Box
-
def
?~(msg: ⇒ String): Failure
Transform an
Empty
to aFailure
with the specified message. -
def
?~!(msg: ⇒ String): Failure
Chain the given
msg
as aFailure
ahead of any failures thisBox
may represent.Chain the given
msg
as aFailure
ahead of any failures thisBox
may represent.If this is an
Empty
, this method behaves like?~
. If it is aFailure
, however, this method returns a newFailure
with the givenmsg
and with itschain
set to thisFailure
.As with
?~
, if this is aFull
, we return it unchanged.- returns
A
Failure
with the message if thisBox
is anEmpty
box. Chain this box to the newFailure
if this is aFailure
. The unchanged box if it is aFull
.
-
def
asA[B](implicit m: Manifest[B]): Box[B]
Create a
Full
box containing the specified value if this box's value is of typeB
andEmpty
otherwise.Create a
Full
box containing the specified value if this box's value is of typeB
andEmpty
otherwise.For example:
scala> Full("boom").asA[Int] res0: net.liftweb.common.Box[Int] = Empty scala> Full(5).asA[Int] res1: net.liftweb.common.Box[Int] = Full(5)
- Definition Classes
- Box
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
choice[B](f1: (Nothing) ⇒ Box[B])(alternative: ⇒ Box[B]): Box[B]
Equivalent to
flatMap(f1).or(alternative)
.Equivalent to
flatMap(f1).or(alternative)
.- Definition Classes
- Box
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
collect[B](pf: PartialFunction[Nothing, B]): Box[B]
If the partial function is defined at the current Box's value, apply the partial function.
If the partial function is defined at the current Box's value, apply the partial function.
- Definition Classes
- Box
-
final
def
collectFirst[B](pf: PartialFunction[Nothing, B]): Box[B]
An alias for
collect
.An alias for
collect
.Although this function is different for true collections, because
Box
is really a collection of 1, the two functions are identical.- Definition Classes
- Box
-
def
compoundFailMsg(msg: ⇒ String): Box[Nothing]
Alias for
?~!
.Alias for
?~!
.- Definition Classes
- Box
-
def
dmap[B](dflt: ⇒ B)(f: (Nothing) ⇒ B): B
Equivalent to
map(f).openOr(dflt)
.Equivalent to
map(f).openOr(dflt)
.- Definition Classes
- Box
-
def
elements: Iterator[Nothing]
Returns an
Iterator
over the value contained in thisBox
, if any. -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(other: Any): Boolean
For
Full
andEmpty
, this has the expected behavior.For
Full
andEmpty
, this has the expected behavior. Equality in terms of Failure checks for equivalence of failure causes:Failure("boom") == Failure("boom") Failure("bam") != Failure("boom") Failure("boom", Full(someException), Empty) != Failure("boom")
For other values, determines equality based upon the contents of this
Box
instead of the box itself. As a result, it is not symmetric. As an example:val foo = "foo" val boxedFoo = Full(foo) foo == boxedFoo //is false boxedFoo == foo //is true
It is safest to use
===
explicitly when you're looking for this behavior, and use==
only for box-to-box comparisons:Full("magic") == Full("magic") Full("magic") != Full("another") Full("magic") != Empty Full("magic") != Failure("something's gone wrong")
- Definition Classes
- Box → Equals → AnyRef → Any
-
def
exists(func: (Nothing) ⇒ Boolean): Boolean
If this
Box
contains a value and it satisfies the specifiedfunc
, returntrue
.If this
Box
contains a value and it satisfies the specifiedfunc
, returntrue
. Otherwise, returnfalse
.- returns
true
if this Box does contain a value and it satisfies the predicate.
- Definition Classes
- Box
-
def
failMsg(msg: ⇒ String): Box[Nothing]
Alias for
?~
. -
def
filter(p: (Nothing) ⇒ Boolean): Box[Nothing]
If this
Box
contains a value and it satisfies the specifiedpredicate
, return theBox
unchanged. -
def
filterMsg(msg: String)(p: (Nothing) ⇒ Boolean): Box[Nothing]
If this
Box
contains a value and it satisfies the specifiedpredicate
, return theBox
unchanged.If this
Box
contains a value and it satisfies the specifiedpredicate
, return theBox
unchanged. Otherwise, return aFailure
with the givenmsg
.- returns
A
Failure
with the message if the box is empty or the predicate is not satisfied by the value contained in this Box.
-
def
filterNot(f: (Nothing) ⇒ Boolean): Box[Nothing]
If this
Box
contains a value and it does not satisfy the specifiedf
, return theBox
unchanged.If this
Box
contains a value and it does not satisfy the specifiedf
, return theBox
unchanged. Otherwise, return anEmpty
.- Definition Classes
- Box
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flatMap[B](f: (Nothing) ⇒ Box[B]): Box[B]
Apply a function returning a
Box
to the value contained in thisBox
if it exists and return the resultingBox
.Apply a function returning a
Box
to the value contained in thisBox
if it exists and return the resultingBox
. If thisBox
is not alreadyFull
, return this box unchanged.- Definition Classes
- Box
- Note
This means that using
flatMap
with aFailure
will preserve theFailure.
-
def
flatten[B](implicit ev: <:<[Nothing, Box[B]]): Box[B]
- Definition Classes
- Box
-
def
forall(func: (Nothing) ⇒ Boolean): Boolean
If this
Box
contains a value and it does not satisfy the specifiedfunc
, returnfalse
.If this
Box
contains a value and it does not satisfy the specifiedfunc
, returnfalse
. Otherwise, returntrue
.- returns
true If the
Box
is empty, or if its value satisfies the predicate.
- Definition Classes
- Box
-
def
foreach[U](f: (Nothing) ⇒ U): Unit
Perform a side effect by calling the specified function with the value contained in this box.
Perform a side effect by calling the specified function with the value contained in this box. The function does not run if this
Box
is empty.- Definition Classes
- Box
-
def
fullXform[T](v: T)(f: (T) ⇒ (Nothing) ⇒ T): T
If the
Box
isFull
, apply the transform functionf
on the valuev
; otherwise, just return the value untransformed.If the
Box
isFull
, apply the transform functionf
on the valuev
; otherwise, just return the value untransformed.The transform function is expected to be a function that will take the value
v
and produce a function from the value in the box to a new value of the same type asv
.For example:
val myBox = Full(10) myBox.fullXForm("No teddy bears left.")({ message => { teddyBears: Int => s"$message Oh wait, there are $teddyBears left!" } })
- T
The type of the initial value, default value, and transformed value.
- returns
If the
Box
isFull
, the value once transformed by the function returned byf
. Otherwise, the initial valuev
.
- Definition Classes
- Box
-
final
def
get: DoNotCallThisMethod
Exists to avoid the implicit conversion from
Box
toOption
.Exists to avoid the implicit conversion from
Box
toOption
. Opening aBox
unsafely should be done usingopenOrThrowException
.This method always throws an exception.
- Definition Classes
- Box
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
isA[B](cls: Class[B]): Box[B]
If this box is
Full
and contains an object of typeB
, returns aFull
of typeBox[B]
.If this box is
Full
and contains an object of typeB
, returns aFull
of typeBox[B]
. Otherwise, returnsEmpty
.This is basically a Java-friendly version of
asA
, which you should prefer when using Scala.For example:
scala> Full("boom").isA(classOf[Int]) res0: net.liftweb.common.Box[Int] = Empty scala> Full(5).isA(classOf[Int]) res1: net.liftweb.common.Box[Int] = Full(5)
- Definition Classes
- Box
-
def
isDefined: Boolean
Returns true if the box contains a value.
Returns true if the box contains a value.
- Definition Classes
- Box
-
def
isEmpty: Boolean
Returns
true
if thisBox
contains no value (i.e., it isEmpty
orFailure
orParamFailure
). -
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
iterator: Iterator[Nothing]
Returns an
Iterator
over the value contained in thisBox
, if any. -
def
javaIterator[B >: Nothing]: Iterator[B]
Get a
java.util.Iterator
from the Box.Get a
java.util.Iterator
from the Box.- Definition Classes
- Box
-
def
map[B](f: (Nothing) ⇒ B): Box[B]
Apply a function to the value contained in this
Box
if it exists and return aFull
containing the result.Apply a function to the value contained in this
Box
if it exists and return aFull
containing the result. If thisBox
is not alreadyFull
, return the unchanged box.- Definition Classes
- Box
- Note
This means that using
map
with aFailure
will preserve theFailure.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
openOr[B](default: ⇒ B): B
Return the value contained in this
Box
if it is full; otherwise return the specified default. -
def
openOrThrowException(justification: ⇒ String): Nothing
The only time when you should be using this method is if the value is guaranteed to be available based on a guard outside of the method.
The only time when you should be using this method is if the value is guaranteed to be available based on a guard outside of the method. In these cases, please provide that information in the justification
String
. For example,User.currentUser.openOrThrowException("This snippet is only used on pages where the user is logged in")
. For tests, use==
or===
instead. See the class documentation for more information.A valid justification for using this method should not be "I want my code to fail fast when I call it." Using exceptions in the core logic of your application should be strongly discouraged.
- justification
Justify why calling this method is okay and why it will not result in an exception being thrown. This serves both as mandatory documentation and as a very clear indication of what unexpected thing happened in the event you were wrong about the guard.
- returns
The contents of the
Box
if it isFull
.
-
def
or[B](alternative: ⇒ Box[B]): Box[B]
Return this Box if
Full
, or the specified alternative if it is empty. -
def
pass(f: (Box[Nothing]) ⇒ Unit): Box[Nothing]
Perform a side effect by passing this
Box
to the specified function and return thisBox
unmodified.Perform a side effect by passing this
Box
to the specified function and return thisBox
unmodified. Similar toforeach
, except thatforeach
returnsUnit
, while this method allows chained use of theBox
.- returns
This box.
- Definition Classes
- Box
-
def
run[T](in: ⇒ T)(f: (T, Nothing) ⇒ T): T
This method calls the specified function with the specified
in
value and the value contained in thisBox
.This method calls the specified function with the specified
in
value and the value contained in thisBox
. If this box is empty, returns thein
value directly.- returns
The result of the function or the
in
value.
- Definition Classes
- Box
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toLeft[B](right: ⇒ B): Either[Nothing, B]
An
Either
that is aRight
with the given argumentright
if this is empty, or aLeft
with the boxed value if this isFull
. -
def
toList: List[Nothing]
Returns a
List
of one element if this is Full, or an empty list if empty. -
def
toOption: Option[Nothing]
Returns the contents of this box wrapped in
Some
if this isFull
, orNone
if this is empty (meaning anEmpty
,Failure
or ParamFailure).
Returns the contents of this box wrapped in
Some
if this isFull
, orNone
if this is empty (meaning anEmpty
,Failure
or ParamFailure).
- Definition Classes
- Box
-
def
toRight[B](left: ⇒ B): Either[B, Nothing]
An
Either
that is aLeft
with the given argumentleft
if this is empty, or aRight
with the boxed value if this isFull
. -
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( ... )
-
def
withFilter(p: (Nothing) ⇒ Boolean): WithFilter
Makes
Box
play better with Scalafor
comprehensions.Makes
Box
play better with Scalafor
comprehensions.- Definition Classes
- Box
-
def
~>[T](errorCode: ⇒ T): ParamFailure[T]
Transform an
Empty
orFailure
to aParamFailure
with the specified type-safe parameter.Transform an
Empty
orFailure
to aParamFailure
with the specified type-safe parameter.- errorCode
A value indicating the error.
- returns
A
ParamFailure
with the specified value, unless this is already aParamFailure
or aFull
. If this is aFailure
, theParamFailure
will preserve the message of theFailure
.