func NewLayeredProxyList
NewLayeredProxyList creates a new LayeredProxyList instance that wraps an existing List
Package lplist provides a layered proxy implementation for lists that allows transparent migration of data between di...
gno.land/p/moul/ulist/lplist/v0LayeredProxyList — a layered proxy over ulist enabling lazy,
append-only schema migration: it wraps a source list with a target list and
transforms source entries only when accessed (source stays immutable), and layers
can be chained for multi-step migrations. Nested under ulist in the monorepo; it
was missed on the original ulist import.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
Dependency graph:

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.
Package lplist provides a layered proxy implementation for lists that allows transparent migration of data between different schema versions.
LayeredProxyList wraps an existing list (source) with a new list (target) and optionally applies migrations to source data when it's accessed. This enables schema evolution without requiring upfront migration of all data, making it ideal for large datasets or when preserving original data is important.
Key features: - Lazy migration: Data is only transformed when accessed, not stored in migrated form - Append-only source: Source data is treated as immutable to preserve original data - Chaining: Multiple LayeredProxyLists can be stacked for multi-step migrations
Example usage:
1// Define data types for different schema versions
2type UserV1 struct {
3 Name string
4 Age int
5}
6
7type UserV2 struct {
8 FullName string
9 Age int
10 Active bool
11}
12
13// Create source list with old schema
14sourceList := ulist.New()
15sourceList.Append(
16 UserV1{Name: "Alice", Age: 30},
17 UserV1{Name: "Bob", Age: 25},
18)
19
20// Define migration function from V1 to V2
21migrateUserV1ToV2 := func(v any) any {
22 user := v.(UserV1)
23 return UserV2{
24 FullName: user.Name, // Name field renamed to FullName
25 Age: user.Age,
26 Active: true, // New field with default value
27 }
28}
29
30// Create layered proxy with migration
31proxy := NewLayeredProxyList(sourceList, migrateUserV1ToV2)
32
33// Add new data directly in V2 format
34proxy.Append(UserV2{FullName: "Charlie", Age: 40, Active: false})
35
36// All access through proxy returns data in V2 format
37for i := 0; i < proxy.Size(); i++ {
38 user := proxy.Get(i).(UserV2)
39 fmt.Printf("User: %s, Age: %d, Active: %t\n", user.FullName, user.Age, user.Active)
40}
NewLayeredProxyList creates a new LayeredProxyList instance that wraps an existing List
LayeredProxyList represents a wrapper around an existing List that handles migration
Append adds one or more values to the target list
Delete marks elements as deleted in the appropriate list
Get retrieves the value at the specified index Uses sourceHeight to efficiently route requests
GetByOffset returns elements starting from offset with count determining direction
GetRange returns elements between start and end indices
GetRangeByOffset returns elements starting from offset
Iterator performs iteration between start and end indices
IteratorByOffset performs iteration starting from offset
MustDelete deletes elements, panicking on error
MustGet retrieves a value, panicking if not found
MustSet updates the value at the specified index, panicking on error
Set updates the value at the specified index
Size returns the total number of active elements
TotalSize returns the total number of elements in the list
MigratorFn is a function type that lazily converts values from source to target