Play NiceLike with the Scala 2.
Returns true if this Box contains no value (is Empty or Failure or ParamFailure)
Returns true if this Box contains no value (is Empty or Failure or ParamFailure)
true if this Box contains no value
If you grew up on Java, you're used to Exceptions as part of your program logic.
If you grew up on Java, you're used to Exceptions as part of your program logic. The Scala philosophy and the Lift philosophy is that exceptions are for exceptional conditions such as failure of an external resource (e.g., your database goes offline) rather than simply indicating that a parameter wasn't supplied or couldn't be parsed.
Lift's Box and Scala's Option provide a mechanism for being explicit about a value existing or not existing rather than relying on a reference being not-null. However, extracting a value from a Box should be done correctly. Correctly can be (in order of use in David Pollak's code): a for comprehension; using map, flatMap or foreach; or using pattern matching.
The only times when you should be using this method are: the value is guaranteed to be available based on a guard outside of the method using the Box or in tests. For example, User.currentUser.openOrThrowException("This snippet is used on pages where the user is logged in")
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.
This method replaces open_! because people used open_! and generally ignored the reason for the "!", so we're making it more explicit that this method should not commonly be used and should be justified when used.
Justify why calling this method is okay and why it will not result in an Exception
The contents of the Box if it has one or an exception if not
Alias for pass
Returns true if the value contained in this box is equal to the specified value.
Transform an Empty to a Failure with the specified message.
Transform an Empty to a Failure with the specified message.
the failure message
a Failure with the message if this Box is Empty
Transform an EmptyBox to a Failure with the specified message and chain the new Failure to any previous Failure represented by this Box.
Transform an EmptyBox to a Failure with the specified message and chain the new Failure to any previous Failure represented by this Box.
the failure message
a Failure with the message if this Box is an Empty Box. Chain the messages if it is already a Failure
Return a Full[B] if the contents of this Box is of type B
, otherwise return Empty
Return a Full[B] if the contents of this Box is of type B
, otherwise return Empty
Apply the function f1 to the contents of this Box if available; if this is empty return the specified alternative.
If the partial function is defined at the current Box's value apply the partial function.
Alias for ?~!
Equivalent to map(f).
Equivalent to map(f).openOr(Full(dflt))
Returns an Iterator over the value contained in this Box
Determines equality based upon the contents of this Box instead of the box itself.
Determines equality based upon the contents of this Box instead of the box itself. As a result, it is not symmetric. Which means that for
val foo = "foo" val boxedFoo = Full(foo) foo == boxedFoo //is false boxedFoo == foo //is true
For Full and Empty, this has the expected behavior. Equality in terms of Failure checks for equivalence of failure causes.
Determine whether this Box contains a value which satisfies the specified predicate
Determine whether this Box contains a value which satisfies the specified predicate
true if this Box does contain a value and it satisfies the predicate
Alias for ?~
Return this Box if it contains a value satisfying the specified predicate; Empty otherwise
Return this Box if it contains a value satisfying the specified predicate; Empty otherwise
this Box if it contains a value satisfying the specified predicate; Empty otherwise
Filter this box on the specified predicate, returning a Failure with the specified message if the predicate is not satisfied.
Filter this box on the specified predicate, returning a Failure with the specified message if the predicate is not satisfied.
the failure message
a predicate
a Failure with the message if the predicate is not satisfied by the value contained in this Box
Creates a Box if the current Box is Full and the value does not satisfy the predicate, f.
Creates a Box if the current Box is Full and the value does not satisfy the predicate, f.
the predicate used to test value.
a Box
Apply a function returning a Box to the value contained in this Box if it exists and return the result, or empty otherwise.
Apply a function returning a Box to the value contained in this Box if it exists and return the result, or empty otherwise.
the modified Box or empty
Determine whether all Box values satisfy the predicate
Determine whether all Box values satisfy the predicate
true if the Box is empty, or if Box's value satisfies the predicate
Perform a side effect by calling the specified function with the value contained in this box.
Return a Full[B] if the contents of this Box is an instance of the specified class, otherwise return Empty
Returns true if the box contains a value.
Returns true if the box contains a value.
true if this Box contains a value
Returns an Iterator over the value contained in this Box
Get a Java Iterator from the Box
Apply a function to the value contained in this Box if it exists and return a new Box containing the result, or empty otherwise.
Apply a function to the value contained in this Box if it exists and return a new Box containing the result, or empty otherwise.
the modified Box or empty
Return the value contained in this Box if it is full; otherwise return the specified default
Return the value contained in this Box if it is full; otherwise return the specified default
the value contained in this Box if it is full; otherwise return the specified default
Return this Box if Full, or the specified alternative if this is empty
Perform a side effect by passing this Box to the specified function and return this Box unmodified.
Perform a side effect by passing this Box to the specified function and return this Box unmodified.
this Box
This method calls the specified function with the value contained in this Box
This method calls the specified function with the value contained in this Box
the result of the function or a default value
An Either
that is a Right
with the given
argument
right
if this is empty, or a Left
if this is
Fill with the Box's value
An Either
that is a Right
with the given
argument
right
if this is empty, or a Left
if this is
Fill with the Box's value
Returns a List of one element if this is Full, or an empty list if empty.
Returns the contents of this box in an Option if this is Full, or None if this is a empty (Empty, Failure or ParamFailure)
An Either
that is a Left
with the given argument
left
if this is empty, or a Right
if this
Full with the Box's value.
An Either
that is a Left
with the given argument
left
if this is empty, or a Right
if this
Full with the Box's value.
Makes Box play better with Scala 2.
Makes Box play better with Scala 2.8 for comprehensions
Transform an Empty to a ParamFailure with the specified typesafe parameter.
Transform an Empty to a ParamFailure with the specified typesafe parameter.
a value indicating the error
a ParamFailure with the specified value
Return the value contained in this Box if it is Full; throw an exception otherwise.
Return the value contained in this Box if it is Full; throw an exception otherwise. Please use openOrThrowException instead. In the past, this method triggered an implicit conversion to Option and could throw an unintended NullPointerException. That is no longer the case, and in Lift 3 this method will be changed to return a useless type so that the compiler will break attempts to use it.
(Since version 2.6) use map/flatMap/foreach if possible, or openOrThrowException if you must
Return the value contained in this Box if it is Full; throw an exception otherwise.
Return the value contained in this Box if it is Full; throw an exception otherwise. This means "don't use it unless you are 100% sure that the Box is Full and you should probably comment your code with the explanation of the guaranty. The better case for extracting the value out of a Box can be found at http://lift.la/scala-option-lift-box-and-how-to-make-your-co
the value contained in this Box if it is full; throw an exception otherwise
(Since version 2.4) use openOrThrowException, or better yet, do the right thing with your code and use map, flatMap or foreach
Return the value contained in this Box if it is Full; throw an exception otherwise.
Return the value contained in this Box if it is Full; throw an exception otherwise.
Using open_! in an example posted to the Lift mailing list may disqualify you for a helpful response.
The method has a '!' in its name. This means "don't use it unless you are 100% sure that the Box is Full and you should probably comment your code with the explanation of the guaranty." The better case for extracting the value out of a Box can be found at http://lift.la/scala-option-lift-box-and-how-to-make-your-co
the value contained in this Box if it is full; throw an exception otherwise
(Since version 2.4) use openOrThrowException, or better yet, do the right thing with your code and use map, flatMap or foreach
The Box class is a container which is able to declare if it is Full (containing a single non-null value) or EmptyBox. An EmptyBox, or empty, can be the Empty singleton, Failure or ParamFailure. Failure and ParamFailure contain information about why the Box is empty including exception information, chained Failures and a String. It serves a similar purpose to the Option class from Scala standard library but adds several features:
Full(1).run("zero") { (x: String, y: Int) => y.toString }
Full(1) $ { x: Box[Int] => println(x openOr 0) }