Skip to content
Back to top
View this page

# Values

Values are instances of types. `Value` is the base class with factory methods for creating and converting values.

When to use: Use values to hold typed data. Primitives are immutable; containers (Vector, Map, Set, XArray) are mutable.

## Quick Start

    from dsviper import Value, ValueString, ValueInt64, ValueVector, TypeVector, Type

    # Direct construction for primitives
    name = ValueString("Alice")
    count = ValueInt64(42)

    # Factory method with type (for containers)
    t_vec = TypeVector(Type.INT64)
    numbers = Value.create(t_vec, [1, 2, 3])

    # Access underlying Python value
    print(name.get())         # "Alice"
    print(list(numbers))      # [1, 2, 3]

    # Check type
    print(name.type())        # string

## Choosing the Right Pattern

Pattern | When to Use | Example
--- | --- | ---
`ValueString("...")` | Direct primitive construction | `ValueInt64(42)`
`Value.create(type, data)` | Generic factory with type | `Value.create(t_vec, [1,2,3])`
`Value.decode(type, bytes)` | Deserialize from binary | `Value.decode(Type.STRING, data)`
`ValueXxx.cast(value)` | Type casting | `ValueInt64.cast(v)`

## Base Class

`dsviper.Value` | A utility class to handle value instantiation and representation.

## Primitive Values

`dsviper.ValueVoid` | A class used to represent a value of type void.
`dsviper.ValueBool` | A class used to represent a value of type bool.
`dsviper.ValueUInt8` | A class used to represent a value of type uint8.
`dsviper.ValueUInt16` | A class used to represent a value of type uint16.
`dsviper.ValueUInt32` | A class used to represent a value of type uint32.
`dsviper.ValueUInt64` | A class used to represent a value of type uint64.
`dsviper.ValueInt8` | A class used to represent a value of type int8.
`dsviper.ValueInt16` | A class used to represent a value of type int16.
`dsviper.ValueInt32` | A class used to represent a value of type int32.
`dsviper.ValueInt64` | A class used to represent a value of type int64.
`dsviper.ValueFloat` | A class used to represent a value of type float.
`dsviper.ValueDouble` | A class used to represent a value of type double.
`dsviper.ValueString` | A class used to represent a value of type string.
`dsviper.ValueBlob` | A class used to represent a value of type blob.
`dsviper.ValueBlobId` | A class used to represent a value of type blob_id.
`dsviper.ValueCommitId` | A class used to represent a value of type commit_id.
`dsviper.ValueUUId` | A class used to represent a value of type uuid.

## Container Values

`dsviper.ValueVector` | A class used to represent a value of type vector<element_type>.
`dsviper.ValueVectorIter` | Iterator for ValueVector elements.
`dsviper.ValueSet` | A class used to represent a value of type set<element_type>.
`dsviper.ValueSetIter` | Iterator for ValueSet elements.
`dsviper.ValueMap` | A class used to represent a value of type map<key_type, element_type>.
`dsviper.ValueMapKeysIter` | Iterator for ValueMap keys.
`dsviper.ValueMapValuesIter` | Iterator for ValueMap values.
`dsviper.ValueMapItemsIter` | Iterator for ValueMap items (key-value pairs).
`dsviper.ValueXArray` | A class used to represent a value of type xarray<element_type>.
`dsviper.ValueOptional` | A class used to represent a value of type optional<element_type>.

## Algebraic Values

`dsviper.ValueTuple` | A class used to represent a value of type tuple<T0, ...>.
`dsviper.ValueTupleIter` | Iterator for ValueTuple elements.
`dsviper.ValueVec` | ValueVec(type_vec [, initial_value]).
`dsviper.ValueMat` | A class used to represent a value of type mat<element_type, columns, rows>.
`dsviper.ValueVariant` | ValueVariant(type_variant, initial_value).
`dsviper.ValueAny` | A class used to represent a value of any type.

## User-Defined Values

`dsviper.ValueStructure` | A class used to represent a value of type struct.
`dsviper.ValueEnumeration` | A class used to represent a value of type struct.
`dsviper.ValueKey` | A class used to represent a value of type key<element_type>.

## Value Program

A `ValueProgram` is a sequence of opcodes that describe mutations to values. Each opcode represents an atomic operation (set, update, union, subtract, etc.).

`dsviper.ValueProgram` | A class used to retreive opcodes.
`dsviper.ValueOpcodeKey` | A class used to retreive the mutation opcodes for an instance of a concept for an attachment.
`dsviper.ValueOpcode` | A utility class to handle opcodes encoder and streamer.
`dsviper.ValueOpcodeDocumentSet` | A class used to represent the type and the arguments of an opcode.
`dsviper.ValueOpcodeDocumentUpdate` | A class used to represent the type and the arguments of a opcode.
`dsviper.ValueOpcodeMapUnion` | A class used to represent the type and the arguments of a opcode.
`dsviper.ValueOpcodeMapSubtract` | A class used to represent the type and the arguments of a opcode.
`dsviper.ValueOpcodeMapUpdate` | A class used to represent the type and the arguments of a opcode.
`dsviper.ValueOpcodeSetUnion` | A class used to represent the type and the arguments of an opcode.
`dsviper.ValueOpcodeSetSubtract` | A class used to represent the type and the arguments of an opcode.
`dsviper.ValueOpcodeXArrayInsert` | A class used to represent the type and the arguments of an opcode.
`dsviper.ValueOpcodeXArrayRemove` | A class used to represent the type and the arguments of an opcode.
`dsviper.ValueOpcodeXArrayUpdate` | A class used to represent the type and the arguments of an opcode.