Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ff27df78
Commit
ff27df78
authored
Sep 07, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new list type which can embed any slice type
parent
627b7c9f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
list.go
ethutil/list.go
+42
-0
No files found.
ethutil/list.go
0 → 100644
View file @
ff27df78
package
ethutil
import
"reflect"
// The list type is an anonymous slice handler which can be used
// for containing any slice type to use in an environment which
// does not support slice types (e.g., JavaScript, QML)
type
List
struct
{
list
reflect
.
Value
Length
int
}
// Initialise a new list. Panics if non-slice type is given.
func
NewList
(
t
interface
{})
*
List
{
list
:=
reflect
.
ValueOf
(
t
)
if
list
.
Kind
()
!=
reflect
.
Slice
{
panic
(
"list container initialized with a non-slice type"
)
}
return
&
List
{
list
,
list
.
Len
()}
}
// Get N element from the embedded slice. Returns nil if OOB.
func
(
self
*
List
)
Get
(
i
int
)
interface
{}
{
if
self
.
list
.
Len
()
>
i
{
return
self
.
list
.
Index
(
i
)
.
Interface
()
}
return
nil
}
// Appends value at the end of the slice. Panics when incompatible value
// is given.
func
(
self
*
List
)
Append
(
v
interface
{})
{
self
.
list
=
reflect
.
Append
(
self
.
list
,
reflect
.
ValueOf
(
v
))
self
.
Length
=
self
.
list
.
Len
()
}
// Returns the underlying slice as interface.
func
(
self
*
List
)
Interface
()
interface
{}
{
return
self
.
list
.
Interface
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment