nustack

refs.items

kv leaves: one value at one address, read and written whole.

Module nustd.kv.refs.items.

kv leaves: one value at one address, read and written whole.

ItemRef is the leaf itself (slot-level read, write, erase and observe over a kv leaf) and declares a slot once for every leaf. Each value leaf mixes one value form in beside it, so the ref is an operand of the value it names; the form decides the surface, the leaf decides where the value lives.

NameSortCallMeaning
BoolRefrefBoolRef(address, parent_ref=None, owner_shape=None)A bool leaf in KV storage, carrying the whole Bool logical surface.
BytesRefrefBytesRef(address, parent_ref=None, owner_shape=None)A bytes leaf in KV storage, carrying the whole Bytes operator surface.
FloatRefrefFloatRef(address, parent_ref=None, owner_shape=None)A float leaf in KV storage, carrying the whole Float operator surface.
IntRefrefIntRef(address, parent_ref=None, owner_shape=None)An int leaf in KV storage, carrying the whole Int operator surface.
ObjectRefrefObjectRef(address, parent_ref=None, owner_shape=None)A leaf in KV storage holding a value of no declared type.
StrRefrefStrRef(address, parent_ref=None, owner_shape=None)A str leaf in KV storage, carrying the whole Str operator surface.

BoolRef

A bool leaf in KV storage, carrying the whole Bool logical surface.

BoolRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.BoolRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Stored as a plain bool, so nothing is translated on read or write.
  • An absent leaf reads as EMPTY, which is not False; test with exists or is_empty when the difference matters.

Example

class Flags(Shape):
    live = BoolRef.slot()
run(Flags.live.set(True), ctx)
run(Flags.live.not_(), ctx)

Inherited methods

From nu.domains.shape.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.item.MutableItemForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.item.ItemForm:

CallBuildsMeaning
.exists()BoolWhether this slot holds a value, as a Bool.
.missing()BoolWhether this slot holds no value, as a Bool: the negation of exists().

From nu.forms.primitives.bool_.Bool:

CallBuildsMeaning
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
a > bBoolSelf strictly greater than other.
a < bBoolSelf strictly less than other.
a >= bBoolSelf greater than or equal to other.
a <= bBoolSelf less than or equal to other.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

BytesRef

A bytes leaf in KV storage, carrying the whole Bytes operator surface.

BytesRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.BytesRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Stored as plain bytes, so nothing is translated on read or write.
  • The leaf a raw payload belongs in: no decoding happens on the way through, unlike the std refs that serialize a domain type.

Example

class Blob(Shape):
    raw = BytesRef.slot()
run(Blob.raw.set(b"payload"), ctx)
run(Blob.raw.hex_(), ctx)

Inherited methods

From nu.domains.shape.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.item.MutableItemForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.item.ItemForm:

CallBuildsMeaning
.exists()BoolWhether this slot holds a value, as a Bool.
.missing()BoolWhether this slot holds no value, as a Bool: the negation of exists().

From nu.forms.primitives.bytes_.Bytes:

CallBuildsMeaning
a + bBytesConcatenation of self and other.
a[key]Bytes | IntByte at an index, or a sub-range by slice.
.len()IntLength of self in bytes.
.contains(item)BoolSubstring test: item in self.
a > bBoolSelf strictly greater than other.
a < bBoolSelf strictly less than other.
a >= bBoolSelf greater than or equal to other.
a <= bBoolSelf less than or equal to other.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
.decode(encoding='utf-8')StrDecode self to a string using the given encoding.
.hex_()StrHex string of self, two digits per byte.
.upper()BytesSelf with ASCII letters uppercased.
.lower()BytesSelf with ASCII letters lowercased.
.strip(chars=None)BytesSelf with leading and trailing bytes removed.
.lstrip(chars=None)BytesSelf with leading bytes removed.
.rstrip(chars=None)BytesSelf with trailing bytes removed.
.split_bytes(sep=None, maxsplit=-1)ListSelf split into a List of Bytes on sep.
.find_bytes(sub, start=0, end=None)IntLowest index of sub in self, or -1 if absent.
.count_bytes(sub)IntNumber of non-overlapping occurrences of sub in self.
.startswith(prefix)BoolSelf starts with prefix.
.endswith(suffix)BoolSelf ends with suffix.
.replace(old, new, count=-1)BytesSelf with occurrences of old replaced by new.
.removeprefix(prefix)BytesSelf with prefix removed if present.
.removesuffix(suffix)BytesSelf with suffix removed if present.
.translate(table, delete=b'')BytesSelf translated through a 256-byte table, with bytes in delete dropped first.
.title()BytesSelf titlecased: each word's first cased byte upper, the rest lower.
.capitalize()BytesSelf with the first byte uppercased and the rest lowercased.
.swapcase()BytesSelf with uppercase and lowercase bytes swapped.
.rsplit_bytes(sep=None, maxsplit=-1)ListSelf split into a List of Bytes on sep, counting maxsplit from the right.
.splitlines(keepends=False)ListSelf split into a List of Bytes at line boundaries.
.partition(sep)TupleSelf split around the first occurrence of sep.
.rpartition(sep)TupleSelf split around the last occurrence of sep.
.rfind_bytes(sub, start=0, end=None)IntHighest index of sub in self, or -1 if absent.
.index_bytes(sub, start=0, end=None)IntLowest index of sub in self.
.rindex_bytes(sub, start=0, end=None)IntHighest index of sub in self.
.isascii()BoolSelf has only ASCII bytes.
.isdigit()BoolSelf has only ASCII digit bytes, and at least one.
.isalpha()BoolSelf has only ASCII letter bytes, and at least one.
.isalnum()BoolSelf has only ASCII alphanumeric bytes, and at least one.
.isspace()BoolSelf has only ASCII whitespace bytes, and at least one.
.istitle()BoolSelf is titlecased, with at least one cased byte.
.isupper()BoolSelf has all cased bytes uppercase, and at least one cased byte.
.islower()BoolSelf has all cased bytes lowercase, and at least one cased byte.
.center(width, fillbyte=b' ')BytesSelf centered in a field of width, padded with fillbyte.
.ljust(width, fillbyte=b' ')BytesSelf left-justified in a field of width, padded with fillbyte.
.rjust(width, fillbyte=b' ')BytesSelf right-justified in a field of width, padded with fillbyte.
.zfill(width)BytesSelf padded with leading zero bytes to width.
.expandtabs(tabsize=8)BytesSelf with tab bytes expanded to spaces.
.join(iterable)BytesSelf used as separator between the elements of iterable.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

FloatRef

A float leaf in KV storage, carrying the whole Float operator surface.

FloatRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.FloatRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Stored as a plain float, so nothing is translated on read or write.
  • Reach for DecimalRef instead when the value is money or anything else that must round-trip exactly.

Example

class Order(Shape):
    price = FloatRef.slot()
run(Order.price.set(12.5), ctx)

Inherited methods

From nu.domains.shape.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.item.MutableItemForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.item.ItemForm:

CallBuildsMeaning
.exists()BoolWhether this slot holds a value, as a Bool.
.missing()BoolWhether this slot holds no value, as a Bool: the negation of exists().

From nu.forms.primitives.float_.Float:

CallBuildsMeaning
a + bFloatSum of self and other.
a - bFloatSelf minus other.
a * bFloatProduct of self and other.
a / bFloatSelf divided by other.
a // bFloatSelf floor-divided by other.
a % bFloatSelf modulo other.
a ** bFloatSelf raised to the other power.
-aFloatNegation of self.
+aFloatSelf unchanged.
abs(a)FloatAbsolute value of self.
a > bBoolSelf strictly greater than other.
a < bBoolSelf strictly less than other.
a >= bBoolSelf greater than or equal to other.
a <= bBoolSelf less than or equal to other.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

IntRef

An int leaf in KV storage, carrying the whole Int operator surface.

IntRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.IntRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Stored as a plain int, so the stored form and the value form are the same and nothing is translated on the way in or out.
  • Arithmetic on the ref builds an expression over the stored value; writing the result back is what set, inc and dec do.

Example

class Counter(Shape):
    hits = IntRef.slot()
run(Counter.hits.set(0), ctx)
run(Counter.hits.inc(), ctx)

Methods

.inc(step=1)

Add step to the stored int and write the result back.

Builds None_.

Arguments

NameTypeDefaultMeaning
stepIntArg1how much to add. May be an expression, not just a literal.

Notes

  • Read-modify-write in one term, not a storage-level atomic increment; wrap it in a transaction when concurrent writers can touch the same leaf.
  • An absent leaf reads as EMPTY, so the addition is EMPTY and the write refuses to store it. Set the slot before incrementing it.

Example

run(Counter.hits.inc(), ctx)

.dec(step=1)

Subtract step from the stored int and write the result back.

Builds None_.

Arguments

NameTypeDefaultMeaning
stepIntArg1how much to subtract. May be an expression.

Notes

  • Same read-modify-write shape as inc, and the same refusal to store a sentinel when the leaf is absent.

Example

run(Counter.hits.dec(2), ctx)

Inherited methods

From nu.domains.shape.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.item.MutableItemForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.item.ItemForm:

CallBuildsMeaning
.exists()BoolWhether this slot holds a value, as a Bool.
.missing()BoolWhether this slot holds no value, as a Bool: the negation of exists().

From nu.forms.primitives.int_.Int:

CallBuildsMeaning
a + bInt | FloatSum of self and other.
a - bInt | FloatSelf minus other.
a * bInt | FloatProduct of self and other.
a / bFloatSelf divided by other.
a // bInt | FloatSelf floor-divided by other.
a % bInt | FloatSelf modulo other.
a ** bInt | FloatSelf raised to the other power.
-aIntNegation of self.
+aIntSelf unchanged.
abs(a)IntAbsolute value of self.
a > bBoolSelf strictly greater than other.
a < bBoolSelf strictly less than other.
a >= bBoolSelf greater than or equal to other.
a <= bBoolSelf less than or equal to other.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
.bitand(other)IntBitwise AND of self and other.
.bitor(other)IntBitwise OR of self and other.
.bitxor(other)IntBitwise XOR of self and other.
.bitnot()IntBitwise NOT of self.
.lshift(other)IntSelf shifted left by other bits.
.rshift(other)IntSelf shifted right by other bits.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

ObjectRef

A leaf in KV storage holding a value of no declared type.

ObjectRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.ObjectRef. Kind Ref, sort ref, cardinality scalar.

What a container descends to when its value is object, undeclared, or a type with no kv leaf of its own. It carries the whole Object surface, so the ref is still an operand: == builds an Eq, attribute and subscript access descend into the value read, and a cast narrows it.

Notes

  • A dict or list stored here reads back as a plain value, not a View.

Example

class Bag(Shape):
    meta = DictRef.slot(object)
run(Bag.meta["title"] == "hello", ctx)
run(nu.Str(Bag.meta["title"]).upper(), ctx)

Inherited methods

From nu.domains.shape.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.item.MutableItemForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.item.ItemForm:

CallBuildsMeaning
.exists()BoolWhether this slot holds a value, as a Bool.
.missing()BoolWhether this slot holds no value, as a Bool: the negation of exists().

From nu.forms.primitives.object_.Object:

CallBuildsMeaning
a + bObjectSum of self and other.
a - bObjectSelf minus other.
a * bObjectProduct of self and other.
a @ bObjectMatrix multiplication: self @ other.
a / bObjectSelf divided by other.
a // bObjectSelf floor-divided by other.
a % bObjectSelf modulo other.
a ** bObjectSelf raised to the other power.
-aObjectNegation of self.
+aObjectSelf unchanged.
abs(a)ObjectAbsolute value of self.
a > bBoolSelf strictly greater than other.
a < bBoolSelf strictly less than other.
a >= bBoolSelf greater than or equal to other.
a <= bBoolSelf less than or equal to other.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
.bitand(other)ObjectPython's & on the values: bits for ints, intersection for sets.
.bitor(other)ObjectPython's | on the values: bits for ints, union for sets, merge for dicts.
.bitxor(other)ObjectPython's ^ on the values: bits for ints, symmetric difference for sets.
.bitnot()ObjectPython's ~ on the value.
.lshift(other)ObjectSelf shifted left by other bits: Python's << on the values.
.rshift(other)ObjectSelf shifted right by other bits: Python's >> on the values.
.union(other)ObjectSet union of self and other.
.intersection(other)ObjectSet intersection of self and other.
.difference(other)ObjectElements of self that are not in other.
.symmetric_difference(other)ObjectElements in exactly one of self and other.
.merge(other)ObjectSelf and other merged into a new mapping: Python's dict |.
a[key]ObjectSubscript access: self[key].
.len()IntLength of self.
.contains(item)BoolMembership test: item in self.
.iter()IteratorLazy iterator stream over self's elements.
.has_attr(name)BoolAttribute presence: hasattr(self, name).

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

StrRef

A str leaf in KV storage, carrying the whole Str operator surface.

StrRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.StrRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Stored as a plain str, so nothing is translated on read or write.
  • Doubles as a key source: a str leaf can be the address of another ref, and it is resolved when the path is walked.

Example

class Portfolio(Shape):
    name = StrRef.slot()
run(Portfolio.name.set("core"), ctx)
run(Portfolio.name.upper(), ctx)

Inherited methods

From nu.domains.shape.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.item.MutableItemForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.item.ItemForm:

CallBuildsMeaning
.exists()BoolWhether this slot holds a value, as a Bool.
.missing()BoolWhether this slot holds no value, as a Bool: the negation of exists().

From nu.forms.primitives.str_.Str:

CallBuildsMeaning
a + bStrConcatenation of self and other.
a[key]StrCharacter at an int index, or substring for a slice.
.len()IntLength of self in characters.
.contains(item)BoolSubstring test: item in self.
a > bBoolSelf strictly greater than other, lexicographically.
a < bBoolSelf strictly less than other, lexicographically.
a >= bBoolSelf greater than or equal to other, lexicographically.
a <= bBoolSelf less than or equal to other, lexicographically.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
.upper()StrSelf converted to uppercase.
.lower()StrSelf converted to lowercase.
.title()StrSelf converted to title case.
.capitalize()StrSelf with only the first character capitalized.
.swapcase()StrSelf with uppercase and lowercase characters swapped.
.casefold()StrSelf folded for aggressive, caseless matching.
.strip(chars=None)StrSelf with leading and trailing characters removed.
.lstrip(chars=None)StrSelf with leading characters removed.
.rstrip(chars=None)StrSelf with trailing characters removed.
.split(sep=None, maxsplit=-1)ListSelf split into a list on sep, from the left.
.rsplit(sep=None, maxsplit=-1)ListSelf split into a list on sep, from the right.
.splitlines(keepends=False)ListSelf split into a list at line boundaries.
.partition(sep)TupleSelf split around the first occurrence of sep into a 3-tuple.
.rpartition(sep)TupleSelf split around the last occurrence of sep into a 3-tuple.
.find(sub, start=0, end=None)IntLowest index in self where sub is found, searching from the left.
.rfind(sub, start=0, end=None)IntHighest index in self where sub is found, searching from the right.
.index(sub, start=0, end=None)IntLowest index in self where sub is found, searching from the left.
.rindex(sub, start=0, end=None)IntHighest index in self where sub is found, searching from the right.
.count_substring(sub)IntCount of non-overlapping occurrences of sub in self.
.startswith(prefix)BoolWhether self starts with prefix.
.endswith(suffix)BoolWhether self ends with suffix.
.isdigit()BoolWhether every character in self is a digit.
.isalpha()BoolWhether every character in self is alphabetic.
.isalnum()BoolWhether every character in self is alphanumeric.
.isspace()BoolWhether every character in self is whitespace.
.isnumeric()BoolWhether every character in self is numeric.
.isdecimal()BoolWhether every character in self is a decimal character.
.isidentifier()BoolWhether self is a valid Python identifier.
.isprintable()BoolWhether every character in self is printable.
.istitle()BoolWhether self is titlecased.
.isupper()BoolWhether every cased character in self is uppercase.
.islower()BoolWhether every cased character in self is lowercase.
.isascii()BoolWhether every character in self is ASCII.
.center(width, fillchar=' ')StrSelf centered in a field of the given width.
.ljust(width, fillchar=' ')StrSelf left-justified in a field of the given width.
.rjust(width, fillchar=' ')StrSelf right-justified in a field of the given width.
.zfill(width)StrSelf padded with leading zeros to the given width.
.expandtabs(tabsize=8)StrSelf with tab characters expanded to spaces.
.replace(old, new, count=-1)StrSelf with occurrences of old replaced by new.
.removeprefix(prefix)StrSelf with the given prefix removed if present.
.removesuffix(suffix)StrSelf with the given suffix removed if present.
.translate(table)StrSelf with characters mapped through a translation table.
.format_map(mapping)StrSelf formatted with {field} placeholders filled from mapping.
.encode(encoding='utf-8')BytesSelf encoded to Bytes.
.join(iterable)StrElements of iterable joined together with self as separator.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

On this page