Skip to content

v1.0.0: Initial implementation#2

Open
mkenney wants to merge 1 commit into
mainfrom
v1.0.0-dev
Open

v1.0.0: Initial implementation#2
mkenney wants to merge 1 commit into
mainfrom
v1.0.0-dev

Conversation

@mkenney
Copy link
Copy Markdown
Member

@mkenney mkenney commented May 21, 2026

No description provided.

@mkenney mkenney marked this pull request as ready for review May 21, 2026 04:27
@mkenney mkenney requested a review from Copilot May 21, 2026 04:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the initial model implementation by expanding core Model functionality (sorting, mapping/filtering/reducing, merging, JSON marshal/unmarshal, iterators) and modernizing types/comments (e.g., any and Go doc comments).

Changes:

  • Added/expanded model operations: sort (by key/value + reverse), merge, map/filter/reduce, and iterator improvements.
  • Refactored internal typing from interface{} to any and improved error propagation in import/unmarshal paths.
  • Updated tests/examples and module dependency on github.com/bdlm/cast/v2.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
value.go Switches internal storage/API returns to any and converts block comments to Go doc comments.
model.types.go Introduces a generic-ish ModelData type constraint.
model.sorter.go Reworks sorting implementation; adds Len, Reverse, and value-comparison helpers.
model.marshaler.go Adds locking during marshal and improves unmarshal/import error handling; updates UnmarshalModel signature/behavior.
model.iterator.go Updates iterator APIs to any and improves list Seek validation.
model.importer.go Refactors import helpers to return errors and uses any-typed containers.
model.go Expands core Model API (New accepts initial data, GetData copies out state, adds Map/Filter/Reduce/Merge, adds read-only enforcement, etc.).
model_test.go Updates construction/signatures and fixes an assertion.
interface.marshaler.go Converts block comments to doc comments; updates UnmarshalModel docs/signature.
go.mod Bumps github.com/bdlm/cast/v2 dependency version.
examples_test.go Updates usage to new New(..., nil) and GetData().
errors.go Adds additional error definitions and converts header comment to doc comment style.
.gitignore Expands ignore patterns (but includes duplicated entries).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread model.types.go
Comment on lines +7 to +9
type ModelData interface {
cast.Tslice | cast.Tmap
}
Comment thread model.iterator.go
}

// Hash model
hashKey := pos.(string)
Comment thread model.go
Comment on lines 58 to 64
if stdModel.ModelTypeList == mdl.GetType() {
k := key.(int)
if k > len(mdl.data) {
k := cast.To[int](key)
if k < 0 || k >= len(mdl.data) {
return errors.WrapE(InvalidIndex, errors.Errorf("index '%d' out of range", k))
}
mdl.data = append(mdl.data[:key.(int)-1], mdl.data[key.(int):]...)
mdl.data = append(mdl.data[:k], mdl.data[k+1:]...)
return nil
Comment thread model.go
Comment on lines 354 to 379
@@ -285,14 +379,32 @@ func (mdl *Model) SetData(data any) error {
return nil
Comment thread model.sorter.go
Sort sorts the model data.
*/
// Len returns the number of items stored in this model.
func (mdl *Model) Len() int {
Comment thread model.sorter.go
Comment on lines +44 to +58
// Sort sorts the model data by the specified flag.
func (mdl *Model) Sort(flag stdSorter.SortFlag) error {
data := []interface{}{}
hashIdx := map[string]int{}
idxHash := map[int]string{}
switch flag {
case stdSorter.SortByKey:
if mdl.locked {
return errors.WrapE(ReadOnlyProperty, errors.Errorf("model is locked"))
}

if flag&stdSorter.SortByKey != 0 {
if stdModel.ModelTypeHash == mdl.GetType() {
order := []string{}
for _, v := range mdl.idxHash {
order = append(order, v)
keys := make([]string, 0, len(mdl.idxHash))
for _, k := range mdl.idxHash {
keys = append(keys, k)
}
sort.Strings(order)
for _, v := range order {
hashIdx[v] = len(data)
idxHash[len(data)] = v
data = append(data, mdl.data[mdl.hashIdx[v]])
sort.Strings(keys)
mdl.data, mdl.hashIdx, mdl.idxHash = rebuildHashIndexes(keys, mdl)
}
Comment thread model.marshaler.go
Comment on lines 14 to 21
if stdModel.ModelTypeList == mdl.GetType() {
return json.Marshal(mdl.data)
}
d := map[string]interface{}{}
d := map[string]any{}
for k, v := range mdl.data {
d[mdl.idxHash[k]] = v
}
return json.Marshal(d)
Comment thread model.go
Comment on lines 124 to 132
case int, int8, int16, int32, int64:
mdl.mux.Lock()
defer mdl.mux.Unlock()
if key.(int) >= int(len(mdl.data)) {
return nil, errors.WrapE(InvalidIndex, errors.Errorf("invalid index '%d'", key.(int)))
k := cast.To[int](key)
if k < 0 || k >= len(mdl.data) {
return nil, errors.WrapE(InvalidIndex, errors.Errorf("invalid index '%d'", k))
}
ret := mdl.data[key.(int)]
return &Value{ret}, nil
return &Value{mdl.data[k]}, nil
default:
Comment thread model.go
Comment on lines 368 to 379
@@ -285,14 +379,32 @@ func (mdl *Model) SetData(data any) error {
return nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants