data

package
v0.0.0-...-ef45db5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package data holds data manipulation functions.

Most functionality should be put into a subpackage of data, but it's acceptable to have small, common, functions here which don't fit into a subpackage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LosslessConvertTo

func LosslessConvertTo[T any](value any) (T, bool)

LosslessConvertTo will attempt to convert a go value into a given type losslessly.

We only want to perform conversions which are ALWAYS lossless, which means:

  • untyped nil -> interface, pointer, slice
  • intX to intY where X <= Y
  • uintX to uintY where X <= Y
  • uintX to intY where X < Y
  • floatX to floatY where X <= Y
  • complexX to complexY where X <= Y
  • string to (string, []byte, []rune)
  • all other conversions implemented by reflect.Value.Convert.

Other conversions to string allowed by reflect.Type.ConvertibleTo are disallowed, because it allows e.g. int->string, but in the sense of string(rune(1938)), which is almost certainly NOT what you want. ConvertibleTo also allows lossy conversions (e.g. int64->int8).

If you arrive here because Assert(t, something, Comparison[else]) worked in a surprising way, you probably need to add more conditions to this function.

Note the "ALWAYS lossless" condition is important - we do not want to allow int64(100) -> int8 even though this hasn't lost data. This is because if the values change, this function will start returning ok=false. We want this conversion to ALWAYS fail with a type conversion error, requiring the caller author to change the input/output types explicitly.

Types

This section is empty.

Directories

Path Synopsis
caching
cache
Package cache implements both in-memory and on-disk caching.
Package cache implements both in-memory and on-disk caching.
cacheContext
Package cacheContext implements a context.Context wrapper which caches the results of Value calls, speeding up subsequent calls for the same key.
Package cacheContext implements a context.Context wrapper which caches the results of Value calls, speeding up subsequent calls for the same key.
lazyslot
Package lazyslot implements a caching scheme for globally shared objects that take significant time to refresh.
Package lazyslot implements a caching scheme for globally shared objects that take significant time to refresh.
lru
Package lru provides least-recently-used (LRU) cache.
Package lru provides least-recently-used (LRU) cache.
Package cmpbin provides binary serialization routines which ensure that the serialized objects maintain the same sort order of the original inputs when sorted bytewise (i.e.
Package cmpbin provides binary serialization routines which ensure that the serialized objects maintain the same sort order of the original inputs when sorted bytewise (i.e.
Package DisjointSet provides a disjoint-set data structure with fixed size.
Package DisjointSet provides a disjoint-set data structure with fixed size.
Package lex64 is a base64 variant that preserves lexicographic ordering of bytestrings.
Package lex64 is a base64 variant that preserves lexicographic ordering of bytestrings.
Package packedintset implements a way to store integer sets in compact form.
Package packedintset implements a way to store integer sets in compact form.
rand
cryptorand
Package cryptorand implements a mockable source or crypto strong randomness.
Package cryptorand implements a mockable source or crypto strong randomness.
mathrand
Package mathrand implements a mockable interface for math/rand.Rand.
Package mathrand implements a mockable interface for math/rand.Rand.
Package recordio implements a basic RecordIO reader and writer.
Package recordio implements a basic RecordIO reader and writer.
Package sortby provides a succinct way to generate correctly-behaved Less functions for use with the stdlib 'sort' package.
Package sortby provides a succinct way to generate correctly-behaved Less functions for use with the stdlib 'sort' package.
Package stringset is an exceedingly simple 'set' implementation for strings.
Package stringset is an exceedingly simple 'set' implementation for strings.
Package strpair implements parsing and formatting of lists of colon-delimited key-value pair strings.
Package strpair implements parsing and formatting of lists of colon-delimited key-value pair strings.
intsetexpr
Package intsetexpr implements parsing of expressions like `a{01..03}b`.
Package intsetexpr implements parsing of expressions like `a{01..03}b`.
pattern
Package pattern implements lightweight parsable string patterns.
Package pattern implements lightweight parsable string patterns.
sanitizehtml
Package sanitizehtml implements a sanitizer of a very limited HTML.
Package sanitizehtml implements a sanitizer of a very limited HTML.
sequence
Package sequence implements matching for sequences of strings.
Package sequence implements matching for sequences of strings.
stringtemplate
Package stringtemplate implements Python string.Template-like substitution.
Package stringtemplate implements Python string.Template-like substitution.
templateproto
Package templateproto defines a proto-based way to configure templates for JSON documents.
Package templateproto defines a proto-based way to configure templates for JSON documents.
units
Package units provides common useful printable units.
Package units provides common useful printable units.
Package treapstore is a lightweight append-only in-memory key-value store built on top a treap (tree + heap) implementation.
Package treapstore is a lightweight append-only in-memory key-value store built on top a treap (tree + heap) implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL