Skip to content
/ splice Public

go1.18 generics implementation of JavaScript's array.splice function for []T where T is constrained to any

License

Notifications You must be signed in to change notification settings

zzwx/splice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

https://github.com/zzwx/splice

Splice

Package splice is a go1.18 generics implementation of JavaScript's array.splice function for []T where T is constrained to any.

v1

For a non-generic string-only version use import "github.com/zzwx/splice".

Example

import "github.com/zzwx/splice/v2"

var months = []string{"Jan", "March", "April", "June"}
splice.Splice(&months, 1, 0, "Feb") // inserts at index 1
fmt.Println(months)
deleted := splice.Splice(&months, 4, 1, "May") // replaces 1 element at index 4
fmt.Println(months)
fmt.Println(deleted)
// Output:
// [Jan Feb March April June]
// [Jan Feb March April May]
// [June]

About

go1.18 generics implementation of JavaScript's array.splice function for []T where T is constrained to any

Topics

Resources

License

Stars

Watchers

Forks

Languages