Value

com.phasmidsoftware.lascala.values.Value
See theValue companion object
sealed trait Value extends Scalar

Trait Value.

The purpose of this trait is to be able to represent quantities -- things that have some ordered (and/or numerical) value -- (or sequences of quantities) in a more meaningful way than simply using "Any".

This trait defines seven methods: source, asBoolean, asValuable, asOrderable, asIncrementable, asFractional, asSequence.

For values that you want to consider as numeric, then use asFractional. Valuable is very similar to Numeric/Fractional but has additional methods, in particular fromString, and these methods typically result in a Try[X] as opposed to X.

For more detail, see Scalar

You can also represent sequences by Value (in particular, SequenceValue). Such values will yield Some(sequence) when asSequence is invoked. Other types of Value will yield None in this situation.

In the vast majority of cases, you can simply provide a String as the input to Value.apply. This is the normal mechanism when you are reading values from HTML, JSON, Config, whatever. Values that derive from String representations are normally StringValues These typically result in an appropriate value when asValuable is invoked, that's to say -- not the String value but the parsed numeric (Valuable) value. If you have a String that you want only to be considered a String, then use QuotedStringValue

Created by scalaprof on 7/8/16.

Attributes

Companion
object
Graph
Supertypes
trait Scalar
class Object
trait Matchable
class Any
Known subtypes
class BooleanValue
class DateValue
class DoubleValue
class IntValue
class StringValue
Show all

Members list

Value members

Concrete methods

def asSequence: Option[Seq[Value]]

View this Value as a Sequence of Value objects.

View this Value as a Sequence of Value objects.

Attributes

Returns

either Some(sequence) or None, as appropriate.

Inherited and Abstract methods

def asBoolean: Option[Boolean]

If this Scalar is a Boolean, then return Some(true) or Some(false) as appropriate. Otherwise, return None.

If this Scalar is a Boolean, then return Some(true) or Some(false) as appropriate. Otherwise, return None.

Attributes

Returns

Some(true), Some(false) or None

Inherited from:
Scalar
def asFractional[X : Fractional]: Option[X]

Transform this Scalar into an (optional) X value which is Fractional

Transform this Scalar into an (optional) X value which is Fractional

Type parameters

X

the type of the result we desire

Attributes

Returns

either Some(x) if this value can be represented so, without information loss; or None otherwise.

Inherited from:
Scalar
def asIncrementable[X](implicit evidence$1: Incrementable[X], pattern: String): Option[X]

Transform this Scalar into an (optional) X value which is Incrementable

Transform this Scalar into an (optional) X value which is Incrementable

Type parameters

X

the type of the result we desire

Attributes

Returns

either Some(x) if this value can be represented so, without information loss; or None otherwise.

Inherited from:
Scalar
def asOrderable[X](implicit evidence$1: Orderable[X], pattern: String): Option[X]

Transform this Scalar into an (optional) X value which is Orderable

Transform this Scalar into an (optional) X value which is Orderable

Type parameters

X

the type of the result we desire

Attributes

Returns

either Some(x) if this value can be represented so, without information loss; or None otherwise.

Inherited from:
Scalar
def asValuable[X : Valuable]: Option[X]

Transform this Scalar into an (optional) X value which is Valuable

Transform this Scalar into an (optional) X value which is Valuable

Type parameters

X

the type of the result we desire

Attributes

Returns

either Some(x) if this value can be represented so, without information loss; or None otherwise.

Inherited from:
Scalar
def defaultFormat: String

The default format for rendering this Scalar object via renderFormatted

The default format for rendering this Scalar object via renderFormatted

Attributes

Inherited from:
Scalar
def get: Any

Method to get the wrapped value as an Any

Method to get the wrapped value as an Any

Attributes

Returns

the value as an Any

Inherited from:
Scalar
def renderFormatted(format: => String): String

Method to show this Scalar simply, obviously and elegantly. Typically, this tries to appear like the source. If you're interested in the Scalar wrapper type, use toString.

Method to show this Scalar simply, obviously and elegantly. Typically, this tries to appear like the source. If you're interested in the Scalar wrapper type, use toString.

Value parameters

format

Used to format the underlying value. If it is null, then we use the source. We are using call-by-name because we don't want this evaluated eagerly since the result of the defaultFormat might change.

Attributes

Returns

a String representing the value which, typically, does not include the wrapper type.

Inherited from:
Scalar
def source: Any

Method to return the source of this Scalar, which may or may not be different from the actual value. In some situations, this may be helpful.

Method to return the source of this Scalar, which may or may not be different from the actual value. In some situations, this may be helpful.

Attributes

Returns

the origin of this Scalar

Inherited from:
Scalar