-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update names of map/builder to work with the seq/builder
- Loading branch information
Showing
12 changed files
with
124 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
package collect | ||
|
||
// write to a map | ||
type Builder interface { | ||
type MapWriter interface { | ||
// add the passed pair to the in-progress map | ||
// returns a new builder ( not guaranteed to be the original one ) | ||
// future: add uniqueness check and error | ||
Add(key string, val any) Builder | ||
// return the completed map | ||
Map() any | ||
// returns a new writer ( not guaranteed to be the original one ) | ||
MapValue(key string, val any) MapWriter | ||
// return the implementation specific representation of a map | ||
GetMap() any | ||
} | ||
|
||
// a function which returns a new builder | ||
// reserve indicates whether to keep space for an blank key | ||
// (ie. comments) | ||
type BuilderFactory func(reserve bool) Builder | ||
// a function which returns a new writer | ||
// reserve indicates whether to keep space for a comment key | ||
type MapFactory func(reserve bool) MapWriter | ||
|
||
// a function which returns a new writer | ||
// reserve indicates whether to keep space for comments | ||
type SequenceFactory func(reserve bool) SequenceWriter | ||
|
||
type SequenceWriter interface { | ||
// add the passed value to the in-progress sequence | ||
// returns a new writer ( not guaranteed to be the original one ) | ||
// indices are guaranteed to increase by one each time | ||
// ( stating with 1 if reserve was true ) | ||
// except for comments, which are written last at index 0 | ||
IndexValue(idx int, val any) SequenceWriter | ||
// return the implementation specific representation of a sequence | ||
GetSequence() any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package stdseq | ||
|
||
import "github.com/ionous/tell/collect" | ||
|
||
type StdSequence []any | ||
|
||
func Make(reserve bool) (ret collect.SequenceWriter) { | ||
if reserve { | ||
ret = StdSequence{""} | ||
} else { | ||
ret = StdSequence{} // nil doesnt work. needs some place for the interface value i guess. | ||
} | ||
return | ||
} | ||
|
||
func (m StdSequence) IndexValue(idx int, val any) (ret collect.SequenceWriter) { | ||
if idx < len(m) { | ||
m[idx] = val | ||
ret = m | ||
} else { | ||
ret = append(m, val) | ||
} | ||
return | ||
} | ||
|
||
// returns []any | ||
func (m StdSequence) GetSequence() any { | ||
return ([]any)(m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.