nustack
ReferenceCore

nu.forms

Typed value interfaces. A Form is what a fabric location holds, wrapped in a fluent typed surface - Int, Str, Dict, ... Two layers:

  • Concrete Forms - the leaf things you write in code (from nu import Str).
  • Abstract Form contracts (forms/collections/abc/) - shared interfaces (SequenceForm, MappingForm, ...), not used directly. These KEEP the Form suffix; concrete Forms dropped it in the rename pass.

Interaction ops that live physically under nu.forms (str/bytes methods, collection ABC interactions) are listed alongside their owning Form so the whole module is searchable from one page.

Primitives

from nu import Any, Bool, Bytes, Float, Int, None_, Str

NameSortSignatureEffectMeaning
AnyFormAny(source)puredynamic/unknown interface - absorbing under all ops, results stay Any; comparison/logical yield Bool
BoolFormBool(source)pureboolean interface - logical + comparable
IntFormInt(source)pureinteger interface - numeric + comparable + logical + bitwise; int/float promotion on mixed arithmetic
FloatFormFloat(source)purefloat interface - numeric + comparable + logical
StrFormStr(source)purestring interface - addable + sliceable + comparable + logical + string methods
BytesFormBytes(source)purebytes interface - sliceable + comparable + logical + bytes methods
None_FormNone_(source=None)purenone interface - logical only

from nu import SentinelForm, EmptyForm, InvalidForm (forms/primitives/sentinel_.py)

NameSortSignatureEffectMeaning
SentinelFormFormSentinelForm[T]purebase for sentinel interfaces (Empty, Invalid) - not instantiated directly
EmptyFormFormEmptyForm()purewraps the EMPTY sentinel - absence of a value
InvalidFormFormInvalidForm()purewraps the INVALID sentinel - invalid/undefined op result

Str interactions

forms/primitives/str_interactions.py - all pure (str is immutable), every op is a ScalarQuery. Reached via Str methods (.upper(), .strip(), ...), not called directly.

NameSortSignatureEffectMeaning
UpperScalarQueryUpper(operand)purestr.upper()
LowerScalarQueryLower(operand)purestr.lower()
TitleScalarQueryTitle(operand)purestr.title()
CapitalizeScalarQueryCapitalize(operand)purestr.capitalize()
SwapCaseScalarQuerySwapCase(operand)purestr.swapcase()
CasefoldScalarQueryCasefold(operand)purestr.casefold()
IsDigitScalarQueryIsDigit(operand)purestr.isdigit()
IsAlphaScalarQueryIsAlpha(operand)purestr.isalpha()
IsAlnumScalarQueryIsAlnum(operand)purestr.isalnum()
IsSpaceScalarQueryIsSpace(operand)purestr.isspace()
IsNumericScalarQueryIsNumeric(operand)purestr.isnumeric()
IsDecimalScalarQueryIsDecimal(operand)purestr.isdecimal()
IsIdentifierScalarQueryIsIdentifier(operand)purestr.isidentifier()
IsPrintableScalarQueryIsPrintable(operand)purestr.isprintable()
IsTitleScalarQueryIsTitle(operand)purestr.istitle()
IsUpperScalarQueryIsUpper(operand)purestr.isupper()
IsLowerScalarQueryIsLower(operand)purestr.islower()
IsAsciiScalarQueryIsAscii(operand)purestr.isascii()
StripScalarQueryStrip(operand, chars)purestr.strip(chars)
LStripScalarQueryLStrip(operand, chars)purestr.lstrip(chars)
RStripScalarQueryRStrip(operand, chars)purestr.rstrip(chars)
SplitScalarQuerySplit(operand, sep, maxsplit)purestr.split(sep, maxsplit)
RSplitScalarQueryRSplit(operand, sep, maxsplit)purestr.rsplit(sep, maxsplit)
SplitLinesScalarQuerySplitLines(operand, keepends)purestr.splitlines(keepends)
FindScalarQueryFind(operand, sub, start, end)purestr.find(sub, start, end)
RFindScalarQueryRFind(operand, sub, start, end)purestr.rfind(sub, start, end)
IndexScalarQueryIndex(operand, sub, start, end)purestr.index(sub, start, end), Invalid if absent
RIndexScalarQueryRIndex(operand, sub, start, end)purestr.rindex(sub, start, end), Invalid if absent
CountSubstringScalarQueryCountSubstring(operand, sub)purestr.count(sub)
StartsWithScalarQueryStartsWith(operand, prefix)purestr.startswith(prefix)
EndsWithScalarQueryEndsWith(operand, suffix)purestr.endswith(suffix)
CenterScalarQueryCenter(operand, width, fillchar)purestr.center(width, fillchar)
LJustScalarQueryLJust(operand, width, fillchar)purestr.ljust(width, fillchar)
RJustScalarQueryRJust(operand, width, fillchar)purestr.rjust(width, fillchar)
ZFillScalarQueryZFill(operand, width)purestr.zfill(width)
ExpandTabsScalarQueryExpandTabs(operand, tabsize)purestr.expandtabs(tabsize)
PartitionScalarQueryPartition(operand, sep)purestr.partition(sep), 3-tuple
RPartitionScalarQueryRPartition(operand, sep)purestr.rpartition(sep), 3-tuple
ReplaceScalarQueryReplace(operand, old, new, count)purestr.replace(old, new, count)
RemovePrefixScalarQueryRemovePrefix(operand, prefix)purestr.removeprefix(prefix)
RemoveSuffixScalarQueryRemoveSuffix(operand, suffix)purestr.removesuffix(suffix)
TranslateScalarQueryTranslate(operand, table)purestr.translate(table)
FormatMapScalarQueryFormatMap(operand, mapping)purestr.format_map(mapping)
EncodeScalarQueryEncode(operand, encoding)purestr.encode(encoding) -> bytes
JoinScalarQueryJoin(operand, iterable)puresep.join(seq)

Bytes interactions

forms/primitives/bytes_interactions.py - all pure (bytes is immutable), every op is a ScalarQuery. Reached via Bytes methods.

NameSortSignatureEffectMeaning
DecodeScalarQueryDecode(operand, encoding)purebytes.decode(encoding) -> str
HexScalarQueryHex(operand)purebytes.hex()
BytesUpperScalarQueryBytesUpper(operand)purebytes.upper()
BytesLowerScalarQueryBytesLower(operand)purebytes.lower()
BytesTitleScalarQueryBytesTitle(operand)purebytes.title()
BytesCapitalizeScalarQueryBytesCapitalize(operand)purebytes.capitalize()
BytesSwapCaseScalarQueryBytesSwapCase(operand)purebytes.swapcase()
BytesStripScalarQueryBytesStrip(operand, chars)purebytes.strip(chars)
BytesLStripScalarQueryBytesLStrip(operand, chars)purebytes.lstrip(chars)
BytesRStripScalarQueryBytesRStrip(operand, chars)purebytes.rstrip(chars)
BytesSplitScalarQueryBytesSplit(operand, sep, maxsplit)purebytes.split(sep, maxsplit)
BytesRSplitScalarQueryBytesRSplit(operand, sep, maxsplit)purebytes.rsplit(sep, maxsplit)
BytesSplitLinesScalarQueryBytesSplitLines(operand, keepends)purebytes.splitlines(keepends)
BytesPartitionScalarQueryBytesPartition(operand, sep)purebytes.partition(sep), 3-tuple
BytesRPartitionScalarQueryBytesRPartition(operand, sep)purebytes.rpartition(sep), 3-tuple
BytesFindScalarQueryBytesFind(operand, sub, start, end)purebytes.find(sub, start, end)
BytesRFindScalarQueryBytesRFind(operand, sub, start, end)purebytes.rfind(sub, start, end)
BytesIndexScalarQueryBytesIndex(operand, sub, start, end)purebytes.index(sub, start, end), Invalid if absent
BytesRIndexScalarQueryBytesRIndex(operand, sub, start, end)purebytes.rindex(sub, start, end), Invalid if absent
BytesCountScalarQueryBytesCount(operand, sub)purebytes.count(sub)
BytesStartsWithScalarQueryBytesStartsWith(operand, prefix)purebytes.startswith(prefix)
BytesEndsWithScalarQueryBytesEndsWith(operand, suffix)purebytes.endswith(suffix)
BytesIsAsciiScalarQueryBytesIsAscii(operand)purebytes.isascii()
BytesIsDigitScalarQueryBytesIsDigit(operand)purebytes.isdigit()
BytesIsAlphaScalarQueryBytesIsAlpha(operand)purebytes.isalpha()
BytesIsAlnumScalarQueryBytesIsAlnum(operand)purebytes.isalnum()
BytesIsSpaceScalarQueryBytesIsSpace(operand)purebytes.isspace()
BytesIsTitleScalarQueryBytesIsTitle(operand)purebytes.istitle()
BytesIsUpperScalarQueryBytesIsUpper(operand)purebytes.isupper()
BytesIsLowerScalarQueryBytesIsLower(operand)purebytes.islower()
BytesCenterScalarQueryBytesCenter(operand, width, fillbyte)purebytes.center(width, fillbyte)
BytesLJustScalarQueryBytesLJust(operand, width, fillbyte)purebytes.ljust(width, fillbyte)
BytesRJustScalarQueryBytesRJust(operand, width, fillbyte)purebytes.rjust(width, fillbyte)
BytesZFillScalarQueryBytesZFill(operand, width)purebytes.zfill(width)
BytesExpandTabsScalarQueryBytesExpandTabs(operand, tabsize)purebytes.expandtabs(tabsize)
BytesReplaceScalarQueryBytesReplace(operand, old, new, count)purebytes.replace(old, new, count)
BytesRemovePrefixScalarQueryBytesRemovePrefix(operand, prefix)purebytes.removeprefix(prefix)
BytesRemoveSuffixScalarQueryBytesRemoveSuffix(operand, suffix)purebytes.removesuffix(suffix)
BytesTranslateScalarQueryBytesTranslate(operand, table, delete)purebytes.translate(table, delete)
BytesJoinScalarQueryBytesJoin(operand, iterable)puresep.join(seq of bytes)

Collections

from nu import Dict, DictItems, DictKeys, DictValues, FrozenSet, Iterator, List, Set, Tuple

NameSortSignatureEffectMeaning
ListFormList[T](source)puremutable sequence interface, comparable
TupleFormTuple[*Ts](source)pureimmutable sequence interface, heterogeneous, comparable
SetFormSet[T](source)puremutable set interface, comparable
FrozenSetFormFrozenSet[T](source)pureimmutable set interface, comparable
DictFormDict[K, V](source)puremutable mapping interface, comparable
DictKeysFormDictKeys[K](source)pureset-like key view over a Dict - lazy, live
DictValuesFormDictValues[V](source)purecollection view over a Dict - iterable, sized, no set ops
DictItemsFormDictItems[K, V](source)pureset-like item view over a Dict - lazy, live
IteratorFormIterator[T](source)purelazy iterator interface - materialize via to_list/to_set/to_tuple

Constructors (per-Form, exported alongside): Dict.create(), Dict.of(**fields), List.create(), Set.create(), FrozenSet.create(), Tuple.create(), Tuple.of(*items) build the underlying ScalarQueryFactory nodes below.

NameSortSignatureEffectMeaning
DictCreateScalarQueryDictCreate()purefresh empty dict
DictOfScalarQueryDictOf(**fields)puredict from named field expressions, {"a": <x>, ...}
ListCreateScalarQueryListCreate()purefresh empty list
TupleCreateScalarQueryTupleCreate()purefresh empty tuple
TupleOfScalarQueryTupleOf(*items)puretuple from positional item expressions
SetCreateScalarQuerySetCreate()purefresh empty set
FrozenSetCreateScalarQueryFrozenSetCreate()purefresh empty frozenset

Collections abc - Form contracts

forms/collections/abc/ - abstract bases, not instantiated directly. KEEP the Form suffix. Mirror collections.abc.

NameSortSignatureEffectMeaning
ContainerFormFormContainerFormpurecontainment capability - .contains(item) -> Bool
SizedFormFormSizedFormpurelength capability - .len() -> Int
SliceableForm[ResultT]FormSliceableForm[ResultT]pureslicing capability - .slice(start, stop, step)
IterableForm[ElementT, CollectionResultT, ElementResultT]FormIterableForm[...]pureiteration capability + result-wrapping infra for subclasses
CollectionForm[ElementT, CollectionResultT, ElementResultT]FormCollectionForm[...]pureSized + Iterable + Container
SequenceForm[CollectionT, ElementT, CollectionResultT, ElementResultT]FormSequenceForm[...]pureCollection + Sliceable + first/last/index_of/count/reversed_keys
MutableSequenceForm[...]FormMutableSequenceForm[...]pureSequence + append/insert/pop/extend/remove/reverse
ReactiveSequenceForm[...]FormReactiveSequenceForm[...]pureMutableSequence + change notifications
MappingForm[CollectionT, KeyT, ValueT, CollectionResultT, ValueResultT]FormMappingForm[...]pureCollection + keys/values/items/get
MutableMappingForm[...]FormMutableMappingForm[...]pureMapping + set_item/del_item/update/pop/popitem/setdefault/clear
ReactiveMappingForm[...]FormReactiveMappingForm[...]pureMutableMapping + change notifications
SetLikeForm[CollectionT, ElementT, CollectionResultT, ElementResultT]FormSetLikeForm[...]pureCollection + union/intersection/difference/symmetric_difference/subset/superset/disjoint/copy + operators
MutableSetForm[...]FormMutableSetForm[...]pureSetLike + add/remove/discard/pop/clear/update/*_update + in-place operators
ReactiveSetForm[...]FormReactiveSetForm[...]pureMutableSet + change notifications

Collections abc - Mapping interactions

forms/collections/abc/mapping_interactions.py - reached via Dict methods (.keys(), .get(), ...), not called directly.

NameSortSignatureEffectMeaning
KeysScalarQueryKeys(mapping)puremapping.keys()
ValuesScalarQueryValues(mapping)puremapping.values()
ItemsScalarQueryItems(mapping)puremapping.items()
GetScalarQueryGet(mapping, key, default)puremapping.get(key, default) or mapping[key] when default is None
ContainsKeyScalarQueryContainsKey(mapping, key)purekey in mapping
CopyScalarQueryCopy(mapping)pureshallow copy, new dict
ReversedKeysScalarQueryReversedKeys(mapping)purereversed(mapping), keys in reverse insertion order
MergeScalarQueryMerge(mapping, other)puremapping | other, new dict
DeleteItemCommandDeleteItem(mapping, key)WRITEdel mapping[key]; mutates slot 0, returns nothing
UpdateCommandUpdate(mapping, other)WRITEmapping.update(other); mutates slot 0, returns nothing
MergeUpdateScalarActionMergeUpdate(mapping, other)WRITEmapping |= other; mutates and yields the mapping
DictPopScalarActionDictPop(mapping, key, default)WRITEmapping.pop(key, default); mutates and yields the popped value
PopItemScalarActionPopItem(mapping)WRITEmapping.popitem(); mutates and yields the (key, value) pair
SetDefaultScalarActionSetDefault(mapping, key, default)WRITEmapping.setdefault(key, default); mutates and yields the value

Collections abc - Sequence interactions

forms/collections/abc/sequence_interactions.py - reached via List methods.

NameSortSignatureEffectMeaning
FirstScalarQueryFirst(seq)pureseq[0], Invalid if empty
LastScalarQueryLast(seq)pureseq[-1], Invalid if empty
IndexOfScalarQueryIndexOf(seq, value)pureseq.index(value), Invalid if not found
CountScalarQueryCount(seq, value)pureseq.count(value)
CopyScalarQueryCopy(seq)purelist.copy(), new list
AppendCommandAppend(seq, value)WRITEseq.append(value); mutates slot 0, returns nothing
InsertCommandInsert(seq, index, value)WRITEseq.insert(index, value); mutates slot 0, returns nothing
ExtendCommandExtend(seq, other)WRITEseq.extend(other); mutates slot 0, returns nothing
RemoveValueCommandRemoveValue(seq, value)WRITEseq.remove(value); mutates slot 0, returns nothing
ReverseCommandReverse(seq)WRITEseq.reverse(); mutates slot 0, returns nothing
SortCommandSort(seq)WRITElist.sort(); mutates slot 0, returns nothing (no-key variant only)
SetIndexCommandSetIndex(seq, index, value)WRITEseq[index] = value; mutates slot 0, returns nothing
DelIndexCommandDelIndex(seq, index)WRITEdel seq[index]; mutates slot 0, returns nothing
PopScalarActionPop(seq, index)WRITEseq.pop(index); mutates and yields the popped value
IAddScalarActionIAdd(seq, other)WRITEseq += other; mutates and returns seq
IMulScalarActionIMul(seq, n)WRITEseq *= n; mutates and returns seq

Collections abc - Set interactions

forms/collections/abc/set_interactions.py - reached via Set / FrozenSet methods.

NameSortSignatureEffectMeaning
UnionScalarQueryUnion(left, right)pureleft.union(right), new set
IntersectionScalarQueryIntersection(left, right)pureleft.intersection(right), new set
DifferenceScalarQueryDifference(left, right)pureleft.difference(right), new set
SymmetricDifferenceScalarQuerySymmetricDifference(left, right)pureleft.symmetric_difference(right), new set
IsSubsetScalarQueryIsSubset(left, right)pureleft <= right
IsSupersetScalarQueryIsSuperset(left, right)pureleft >= right
IsDisjointScalarQueryIsDisjoint(left, right)pureleft.isdisjoint(right)
CopyScalarQueryCopy(s)pures.copy(), new set
SetOrScalarQuerySetOr(left, right)pureleft | right, new set
SetAndScalarQuerySetAnd(left, right)pureleft & right, new set
SetSubScalarQuerySetSub(left, right)pureleft - right, new set
SetXorScalarQuerySetXor(left, right)pureleft ^ right, new set
AddCmdCommandAddCmd(s, value)WRITEs.add(value); mutates the set, returns nothing
RemoveCommandRemove(s, value)WRITEs.remove(value); mutates the set, returns nothing
DiscardCommandDiscard(s, value)WRITEs.discard(value); mutates the set, returns nothing
SetUpdateCommandSetUpdate(s, other)WRITEs.update(other); mutates the set, returns nothing
IntersectionUpdateCommandIntersectionUpdate(s, other)WRITEs.intersection_update(other); mutates the set, returns nothing
DifferenceUpdateCommandDifferenceUpdate(s, other)WRITEs.difference_update(other); mutates the set, returns nothing
SymmetricDifferenceUpdateCommandSymmetricDifferenceUpdate(s, other)WRITEs.symmetric_difference_update(other); mutates the set, returns nothing
SetPopScalarActionSetPop(s)WRITEs.pop(); mutates the set, yields the removed element
SetIOrScalarActionSetIOr(left, right)WRITEleft |= right; mutates and returns the set
SetIAndScalarActionSetIAnd(left, right)WRITEleft &= right; mutates and returns the set
SetISubScalarActionSetISub(left, right)WRITEleft -= right; mutates and returns the set
SetIXorScalarActionSetIXor(left, right)WRITEleft ^= right; mutates and returns the set

Collections abc - Shared interactions

forms/collections/abc/shared_interactions.py - shared across mutable collections.

NameSortSignatureEffectMeaning
ClearCommandClear(collection)WRITEcollection.clear(); mutates the collection, returns nothing

On this page