Scalar

com.phasmidsoftware.lascala.values.Scalar
See theScalar companion object
trait Scalar

Trait Scalar.

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

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

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 values that you want to consider as orderable, then use asOrderable. Orderable extends Ordering. It is used for the type of quantities that do not support arithmetic operations, but do support ordering. A prime example is Date, Datetime, etc.

In the vast majority of cases, you can simply provide a String as the input to Scalar.apply. This is the normal mechanism when you are reading values from HTML, JSON, Config, whatever. Scalars that derive from String representations are normally StringScalars 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 QuotedStringScalar

Created by scalaprof on 8/4/16.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

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

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.

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.

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.

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.

def defaultFormat: String

The default format for rendering this Scalar object via renderFormatted

The default format for rendering this Scalar object via renderFormatted

Attributes

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

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.

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