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 Objecttrait Matchableclass Any
- Known subtypes
-
class BaseScalarclass BaseBooleanScalarclass BooleanScalarclass BooleanValueclass BaseDateScalarclass DateScalarclass DateValueclass BaseDoubleScalarclass DoubleScalarclass DoubleValueclass BaseIntScalarclass IntScalarclass IntValueclass BaseQuotedStringScalarclass QuotedStringScalarclass QuotedStringValueclass BaseRationalScalarclass RationalScalarclass RationalValueclass BaseStringScalarclass StringScalarclass StringValueclass SequenceValuetrait Value