SkillAgentSearch skills...

List

šŸ“ A generic list implementation in Go for easy functional programming

Install / Use

/learn @atomicgo/List
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ │ │ IMPORTANT NOTE │ │ │ │ This file is automatically generated │ │ All manual modifications will be overwritten │ │ │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ --> <h1 align="center">AtomicGo | list</h1> <p align="center"> <img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fatomicgo.dev%2Fapi%2Fshields%2Flist&style=flat-square" alt="Downloads"> <a href="https://github.com/atomicgo/list/releases"> <img src="https://img.shields.io/github/v/release/atomicgo/list?style=flat-square" alt="Latest Release"> </a> <a href="https://codecov.io/gh/atomicgo/list" target="_blank"> <img src="https://img.shields.io/github/actions/workflow/status/atomicgo/list/go.yml?style=flat-square" alt="Tests"> </a> <a href="https://codecov.io/gh/atomicgo/list" target="_blank"> <img src="https://img.shields.io/codecov/c/gh/atomicgo/list?color=magenta&logo=codecov&style=flat-square" alt="Coverage"> </a> <a href="https://codecov.io/gh/atomicgo/list"> <!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-23-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end --> </a> <a href="https://opensource.org/licenses/MIT" target="_blank"> <img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square" alt="License: MIT"> </a> <a href="https://goreportcard.com/report/github.com/atomicgo/list" target="_blank"> <img src="https://goreportcard.com/badge/github.com/atomicgo/list?style=flat-square" alt="Go report"> </a> </p>
<p align="center"> <strong><a href="https://pkg.go.dev/atomicgo.dev/list#section-documentation" target="_blank">Documentation</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md" target="_blank">Contributing</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CODE_OF_CONDUCT.md" target="_blank">Code of Conduct</a></strong> </p>
<p align="center"> <img src="https://raw.githubusercontent.com/atomicgo/atomicgo/main/assets/header.png" alt="AtomicGo"> </p> <p align="center"> <table> <tbody> </tbody> </table> </p> <h3 align="center"><pre>go get atomicgo.dev/list</pre></h3> <p align="center"> <table> <tbody> </tbody> </table> </p> <!-- gomarkdoc:embed:start --> <!-- Code generated by gomarkdoc. DO NOT EDIT -->

list

import "atomicgo.dev/list"

Package list implements a generic list. It is a wrapper around a slice and has multiple useful methods. It can be used to develop in a functional style, but it is not required. The main purpose of this package is, to make working with slices easier. The package supports sorting, shuffling, filtering, mapping, appending, prepending, removing, inserting and more.

Index

<a name="List"></a>

type List

List is a generic list type.

type List[T any] struct {
    // contains filtered or unexported fields
}
package main

import (
	"fmt"
	"strings"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")

	l.Map(func(s string) string {
		return s + "!"
	}).Filter(func(s string) bool {
		return !strings.Contains(s, "b")
	})

	fmt.Println(l)
}

Output

[a! c!]

<a name="SliceToList"></a>

func SliceToList

func SliceToList[T any](items []T) List[T]

SliceToList converts a slice to a list.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	l := list.SliceToList([]string{"a", "b", "c"})

	fmt.Println(l)
}

Output

[a b c]

<a name="List[T].Append"></a>

func (*List[T]) Append

func (l *List[T]) Append(items ...T) *List[T]

Append adds items to the end of list.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")

	fmt.Println(l)
}

Output

[a b c]

<a name="List[T].Clear"></a>

func (*List[T]) Clear

func (l *List[T]) Clear() *List[T]

Clear removes all items from the list.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")
	l.Clear()

	fmt.Println(l)
}

Output

[]

<a name="List[T].Contains"></a>

func (List[T]) Contains

func (l List[T]) Contains(item T) bool

Contains returns true if the list contains the given item.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")

	fmt.Println(l.Contains("b"))
}

Output

true

<a name="List[T].Copy"></a>

func (*List[T]) Copy

func (l *List[T]) Copy() *List[T]

Copy returns a new copy of the list. Useful when you want to modify a list without modifying the original.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")

	fmt.Println(l.Append("appended"))         // Overwrites the original list
	fmt.Println(l.Copy().Append("appended1")) // Does not overwrite the original list
	fmt.Println(l.Copy().Append("appended2")) // Does not overwrite the original list
	fmt.Println(l)
}

Output

[a b c appended]
[a b c appended appended1]
[a b c appended appended2]
[a b c appended]

<a name="List[T].Filter"></a>

func (*List[T]) Filter

func (l *List[T]) Filter(f func(T) bool) *List[T]

Filter removes all items from the list that do not match the given predicate.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")

	l.Filter(func(s string) bool {
		return s != "b"
	})

	fmt.Println(l)
}

Output

[a c]

<a name="List[T].ForEach"></a>

func (List[T]) ForEach

func (l List[T]) ForEach(f func(T))

ForEach iterates over the list and calls the given function for each item.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")
	l.ForEach(func(s string) {
		fmt.Println(s)
	})
}

Output

a
b
c

<a name="List[T].Get"></a>

func (*List[T]) Get

func (l *List[T]) Get(i int) T

Get returns the item at the given index.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")

	fmt.Println(l.Get(1))
}

Output

b

<a name="List[T].IndexOf"></a>

func (List[T]) IndexOf

func (l List[T]) IndexOf(item T) int

IndexOf returns the index of the first occurrence of the given item.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")

	fmt.Println(l.IndexOf("b"))
}

Output

1

<a name="List[T].Insert"></a>

func (*List[T]) Insert

func (l *List[T]) Insert(i int, items ...T) *List[T]

Insert adds items at the given index.

package main

import (
	"fmt"

	"atomicgo.dev/list"
)

func main() {
	var l list.List[string]

	l.Append("a", "b", "c")
	l.Insert(1, "inserted")
	fmt.Println(l)

	l.Insert(0, "a", "b", "c")
	fmt.Println(l)
}

Output

[a inserted b c]
[a b c a inserted b c]

<a n

View on GitHub
GitHub Stars11
CategoryDevelopment
Updated1y ago
Forks0

Languages

Go

Security Score

80/100

Audited on Feb 14, 2025

No findings