slice

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 4 Imported by: 1

README ΒΆ

Slice

Slice is a Go package that provides a generic slice with extended functionality. It abstracts common list operations, such as appending, deleting, concatenating, mapping, and more, making it easier to work with slices in Go.

Slice

PkgGoDev Go Report Card GitHub release (latest by date) GitHub Contributor Covenant

Features

πŸ• Enhanced Functionality

Slice simplifies the complexities of slice manipulation in Go, streamlining your code by offering a rich set of operations.

🍰 Seamless Integration

Incorporating Slice into your Go projects is effortless. Simply import the package, specify the type, and harness its capabilities right away.

πŸ§€ Type Generic

Slice embraces generics, empowering you to store and slice data flexibly and efficiently.

πŸ₯© Access Safety

Slice enhances code robustness by addressing common programming pitfalls, including null pointer dereferences and out-of-bounds array accesses. Your code stays safe and reliable.

Installation

You can install it in your Go project using go get:

go get github.com/lindsaygelle/slice

Usage

Import the package into your Go code:

import (
	"github.com/lindsaygelle/slice"
)

Methods

Provided methods for &slice.Slice[T].

Append

Appends values to the end of the slice and returns a pointer to the modified slice.

s := &slice.Slice[int]{1, 2, 3}
s.Append(4, 5) // s is now [1, 2, 3, 4, 5]
AppendFunc

Appends selected elements to the end of the slice based on a provided condition.

s := &slice.Slice[int]{}
s.AppendFunc(func(i int, value int) bool {
	return value%2 == 0 // Append even numbers to the Slice.
}, 1, 2, 3, 4, 5)
AppendLength

Appends values to the end of the slice and returns the length of the modified slice.

s := &slice.Slice[int]{1, 2, 3}
length := s.AppendLength(4, 5) // s is now [1, 2, 3, 4, 5], length is 5
Bounds

Checks if an index is within the valid range of indices for the slice.

s := &slice.Slice[int]{1, 2, 3}
inBounds := s.Bounds(1) // inBounds is true
outOfBounds := s.Bounds(5) // outOfBounds is false
Clone

Creates a duplicate of the current slice with a reference to a new pointer.

s1 := &slice.Slice[int]{1, 2}
s2 := s1.Clone()
s2.Replace(0, 3) // s1 is still [1, 2], s2 is [3, 2]
Concatenate

Merges elements from another slice to the tail of the receiver slice.

s1 := &slice.Slice[int]{1, 2, 3}
s2 := &slice.Slice[int]{4, 5}
s1.Concatenate(s2) // s1 is now [1, 2, 3, 4, 5]
ConcatenateFunc

Appends elements from another slice based on a filtering function.

s1 := &slice.Slice[int]{1, 2, 3}
s2 := &slice.Slice[int]{4, 5, 6}
s1.ConcatenateFunc(s2, func(i int, value int) bool {
	return value%2 == 0
}) // s1 is now [1, 2, 3, 4, 6]
ConcatenateLength

Merges elements from another slice to the tail of the receiver slice and returns the length of the modified slice.

s1 := &slice.Slice[int]{1, 2, 3}
s2 := &slice.Slice[int]{4, 5}
length := s1.ConcatenateLength(s2) // s1 is now [1, 2, 3, 4, 5], length is 5
Contains

Checks if a value exists in the slice.

s := &slice.Slice[string]{"apple", "banana", "cherry"}
containsBanana := s.Contains("banana") // containsBanana is true
ContainsMany

Checks if multiple values exist in the slice and returns a boolean slice indicating their presence.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
result := s.ContainsMany(2, 4, 6) // result will be [true, true, false]
Delete

Safely removes an element from the slice by index.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
s.Delete(2) // s is now [1, 2, 4, 5]
DeleteFunc

Safely removes elements from the slice based on a provided predicate function.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
even := func(i int, value int) bool { return value%2 == 0 }
s.DeleteFunc(even) // 's' will contain [1, 3, 5] after removing even elements.
DeleteLength

Safely removes an element from the slice by index and returns the new length of the modified slice.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
newLength := s.DeleteLength(2) // s is now [1, 2, 4, 5], newLength is 4
DeleteOK

Safely removes an element from the slice by index and returns a boolean indicating the success of the operation.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
deleted := s.DeleteOK(2) // s is now [1, 2, 4, 5], deleted is true
DeleteUnsafe

Removes an element from the slice by index. Panics if index is out of bounds.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
s.DeleteUnsafe(2)
// The slice becomes [1, 2, 4, 5] with the element at index 2 (value 3) removed.
Each

Executes a provided function for each element in the slice.

s := &slice.Slice[string]{"apple", "banana", "cherry"}
s.Each(func(i int, value string) {
	fmt.Printf("Element %d: %s\n", i, value)
})
EachBreak

Executes a provided function for each element in the slice with an optional break condition.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
s.EachBreak(func(i int, value int) bool {
	fmt.Printf("Element %d: %d\n", i, value)
	return i < 3 // Stop iteration when i is less than 3
})
EachReverse

Executes a provided function for each element in reverse order.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
s.EachReverse(func(i int, value int) {
	fmt.Printf("Element %d: %d\n", i, value)
})
EachReverseBreak

Executes a provided function for each element in reverse order with an optional break condition.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
s.EachReverseBreak(func(i int, value int) bool {
	fmt.Printf("Element %d: %d\n", i, value)
	return i > 2 // Stop iteration when i is greater than 2
})
Equal

Checks if the two slices are equal.

s1 := slice.Slice[int]{1, 2, 3}
s2 := slice.Slice[int]{1, 2, 3}
equal := s1.Equal(s2) // true
EqualFunc

Checks whether the slices are equal based on the filtering function.

s1 := slice.Slice[int]{1, 2, 3}
s2 := slice.Slice[int]{2, 4, 6}
customEqual := func(i int, value1, value2 int) bool {
    return value1*2 == value2
}
equal := s1.EqualFunc(s2, customEqual) // true.
Fetch

Retrieves the element at a specified index in the slice.

s := &slice.Slice[string]{"apple", "banana", "cherry"}
fruit := s.Fetch(1) // fruit will be "banana"
FetchLength

Retrieves the element at a specified index in the slice and the length of the slice.

s := &slice.Slice[int]{10, 20, 30, 40, 50}
value, length := s.FetchLength(2)
// value will be 30
// length will be 5
Filter

Creates a new slice containing elements that satisfy a given predicate function.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
filtered := s.Filter(func(x int) bool {
	return x%2 == 0  Keep only even numbers
}) // filtered will be &Slice[int]{2, 4}
FindIndex

Finds the index of the first element that satisfies a given predicate function.

s := &slice.Slice[string]{"apple", "banana", "cherry"}
index, found := s.FindIndex(func(fruit string) bool {
	return fruit == "banana"
})
// index will be 1
// found will be true
Get

Retrieves the element at a specified index in the slice and returns a boolean indicating success.

s := &slice.Slice[float64]{3.14, 2.71, 1.61}
value, ok := s.Get(1)
// value will be 2.71
// ok will be true
GetLength

Retrieves the element at a specified index in the slice, the length of the slice, and a boolean indicating success.

s := &slice.Slice[int]{10, 20, 30, 40, 50}
value, length, ok := s.GetLength(2)
// value will be 30
// length will be 5
// ok will be true
IsEmpty

Checks if the slice is empty.

s := &slice.Slice[int]{}
isEmpty := s.IsEmpty() // isEmpty will be true
IsPopulated

Checks if the slice is not empty.

s := &slice.Slice[int]{10, 20, 30}
isPopulated := s.IsPopulated() // isPopulated will be true
Length

Returns the number of elements in the slice.

s := &slice.Slice[int]{10, 20, 30, 40, 50}
length := s.Length() // length will be 5
Make

Empties the slice and sets it to a specified length.

s := &slice.Slice[int]{10, 20, 30}
s.Make(3) // s will be an empty Slice of length 3
MakeEach

Empties the slice, sets it to a specified length, and populates it with provided values.

s := &slice.Slice[int]{}
s.MakeEach(10, 20, 30) // s will be a Slice containing {10, 20, 30}
MakeEachReverse

Empties the slice, sets it to a specified length, and populates it with provided values in reverse order.

s := &slice.Slice[int]{}
s.MakeEachReverse(10, 20, 30) //  s will be a Slice containing {30, 20, 10}
Map

Executes a provided function for each element and sets the returned value to the current index.

s := &slice.Slice[int]{10, 20, 30}
s.Map(func(i int, value int) int {
	return value * 2
}) // s will be a Slice containing {20, 40, 60}
MapReverse

Executes a provided function for each element in reverse order and sets the returned value to the current index.

s := &slice.Slice[int]{10, 20, 30}
s.MapReverse(func(i int, value int) int {
	return value * 2
}) // s will be a Slice containing {60, 40, 20}
Modify

Modify applies the provided function to each element in the slice and modifies the elements in place.

s := slice.Slice[int]{1, 2, 3, 4, 5}
modifiedSlice := numbers.Modify(func(i int, value int) int {
    return value * 2
})
// modifiedSlice: [2, 4, 6, 8, 10]
Poll

Removes and returns the first element from the slice.

s := &slice.Slice[int]{10, 20, 30}
value := s.Poll() // value will be 10, and s will be [20, 30].
PollLength

Removes the first element from the slice and returns the removed element and the length of the modified slice.

s := &slice.Slice[int]{10, 20, 30}
value, length := s.Poll() // value will be 10, length will be 2, and s will be [20, 30]
PollOK

Removes and returns the first element from the slice and returns a boolean indicating success.

s := slice.Slice[int]{1, 2, 3}
value, ok := s.PollOK() // 'value' will be 1, and 'ok' will be true as the slice is not empty.
Pop

Removes and returns the last element from the slice.

s := &slice.Slice[int]{1, 2, 3}
value := s.Pop()
// 'value' will be 3, and the slice will become [1, 2].
PopLength

Removes the last element from the slice and returns the removed element and the length of the modified slice.

s := &slice.Slice[int]{10, 20, 30}
value, length := s.PopLength() // value will be 30, length will be 2, and s will be [10, 20]
PopOK

Removes and returns the last element from the slice and returns a boolean indicating success.

s := &slice.Slice[int]{10, 20, 30}
value, ok := s.PopOK() // value will be 30, ok will be true, and s will be [10, 20]
Precatenate

Merges elements from another slice to the head of the receiver slice.

s1 := &slice.Slice[int]{1, 2, 3}
s2 := &slice.Slice[int]{4, 5}
s1.Precatenate(s2) // s1 will be [4, 5, 1, 2, 3]
PrecatenateFunc

Prepends elements from another slice based on a provided predicate function.

s1 := &slice.Slice[int]{1, 2, 3}
s2 := &slice.Slice[int]{4, 5, 6}
result := s1.PrecatenateFunc(s2, func(i int, value int) bool {
	return value%2 == 0
})  // s1 will be modified to [6, 4, 2, 1, 3], and 'result' will be a pointer to 's1'.
PrecatenateLength

Merges elements from another slice to the head of the receiver slice and returns the length of the modified slice.

s1 := &slice.Slice[int]{1, 2, 3}
s2 := &slice.Slice[int]{4, 5}
length := s1.PrecatenateLength(s2) // length will be 5, and s1 will be [4, 5, 1, 2, 3]
Prepend

Adds one element to the head of the slice.

s := &slice.Slice[int]{2, 3}
s.Prepend(1) // s will be [1, 2, 3]
PrependFunc

Prepends elements to the head of the slice based on a provided predicate function.

s := &slice.Slice[int]{1, 2, 3}
result := s.PrependFunc(func(i int, value int) bool {
	return value%2 == 0
}, 4, 5, 6) // 's' will be modified to [6, 4, 2, 1, 3], and 'result' will be a pointer to 's'.
PrependLength

Adds multiple elements to the head of the slice and returns the length of the modified slice.

s := &slice.Slice[int]{2, 3}
length := s.PrependLength(1, 0) // length will be 4, and s will be [1, 0, 2, 3]
Reduce

Reduce applies the provided function to each element in the slice and reduces the elements to a single value.

s := slice.Slice[int]({1, 2, 3, 4, 5})
sum := numbers.Reduce(func(i int, currentValue int, resultValue int) int {
    return resultValue + currentValue
})
// sum: 15 (1 + 2 + 3 + 4 + 5)
ReduceReverse

ReduceReverse iterates over the slice in reverse order and reduces the elements into a single value using the provided function.

s := slice.Slice[int]{1, 2, 3, 4, 5}
sum := numbers.ReduceReverse(func(i int, currentValue, resultValue int) int {
    return currentValue + resultValue
})
// sum: 15 (sum of all elements in the slice)
Replace

Replaces the element at the index with the provided value.

s := &slice.Slice[int]{1, 2, 3}
ok := s.Replace(1, 4) // ok will be true, and s will be [1, 4, 3]
Reverse

Reverses the order of the slice.

s := &slice.Slice[int]{1, 2, 3}
s.Reverse() // s will be [3, 2, 1]
Set

Creates a new slice containing opnly unique values.

s := &slice.Slice[int]{1, 2, 2, 3, 3, 3}
s.Set() // s will be [1, 2, 3]
Shuffle

Randomly shuffles elements in the slice.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
s.Shuffle() // s will be a random permutation of [1, 2, 3, 4, 5]
Slice

Creates a subset of the values based on the beginning and end index.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
newSlice := s.Slice(1, 3) // newSlice will be [2, 3, 4]
Splice

Modifies the slice to include only the values based on the beginning and end index.

s := &slice.Slice[int]{1, 2, 3, 4, 5}
slice.Split(1, 3) // s will be [2, 3, 4]
SortFunc

Sorts elements in the slice that satisfy a provided predicate function.

s := &slice.Slice[int]{2, 1, 5, 3}
s.SortFunc(func(i int, j int, a int, b int) bool {
	return a < b
}) // s will be [1, 2, 3, 5]
Swap

Swaps values at indexes i and j.

s := &slice.Slice[int]{1, 2, 3}
s.Swap(0, 2) // s will be [3, 2, 1]

Examples

Struct
// Define a custom struct
type Person struct {
    Name  string
    Age   int
    Email string
}

// Create a slice of Person structs
people := &slice.Slice[Person]{
    {Name: "Alice", Age: 30, Email: "alice@example.com"},
    {Name: "Bob", Age: 25, Email: "bob@example.com"},
}

// Append a new person to the slice
newPerson := Person{Name: "Charlie", Age: 35, Email: "charlie@example.com"}
people.Append(newPerson)

// Find the index of a person with a specific email address
index := people.FindIndex(func(p Person) bool {
    return p.Email == "bob@example.com"
})

// Slice the slice to include only people aged 30 or older
people.Slice(1, people.Length())

// Reverse the order of people in the slice
people.Reverse()

// Iterate over the slice and print each person's details
people.Each(func(index int, person Person) {
    fmt.Printf("Index %d: Name: %s, Age: %d, Email: %s\n", index, person.Name, person.Age, person.Email)
})
Chaining
s := (&slice.Slice[int64]{1, 2, 3}).Append(4, 5, 6).Filter(func(_ int, value int64) bool {
  return value%2 == 0
})
fmt.Println(s) // 2, 4, 6

Docker

A Dockerfile is provided for individuals that prefer containerized development.

Building

Building the Docker container:

docker build . -t slice
Running

Developing and running Go within the Docker container:

docker run -it --rm --name slice slice

Docker Compose

A docker-compose file has also been included for convenience:

Running

Running the compose file.

docker-compose up -d

Contributing

We warmly welcome contributions to Slice. Whether you have innovative ideas, bug reports, or enhancements in mind, please share them with us by submitting GitHub issues or creating pull requests. For substantial contributions, it's a good practice to start a discussion by creating an issue to ensure alignment with the project's goals and direction. Refer to the CONTRIBUTING file for comprehensive details.

Branching

For a smooth collaboration experience, we have established branch naming conventions and guidelines. Please consult the BRANCH_NAMING_CONVENTION document for comprehensive information and best practices.

License

Slice is released under the MIT License, granting you the freedom to use, modify, and distribute the code within this repository in accordance with the terms of the license. For additional information, please review the LICENSE file.

Security

If you discover a security vulnerability within this project, please consult the SECURITY document for information and next steps.

Code Of Conduct

This project has adopted the Amazon Open Source Code of Conduct. For additional information, please review the CODE_OF_CONDUCT file.

Acknowledgements

Big thanks to egonelbre/gophers for providing the delightful Gopher artwork used in the social preview. Don't hesitate to pay them a visit!

Documentation ΒΆ

Overview ΒΆ

Package slice is a Go package that offers a generic slice with extended functionality. It abstracts common list operations, such as appending, deleting, concatenating, mapping, and more, making it easier to work with slices in Go.

Index ΒΆ

Examples ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Slice ΒΆ

type Slice[T any] []T

Slice is a generic list-like struct that allows for the manipulation and traversal of elements by numeric index. It is parameterized with the type T, allowing it to work with slices of any data type.

Example usage:.

// Create a Slice of integers.
s := &slice.Slice[int]{1, 2, 3, 4, 5}.

// Append values to the Slice.
s.Append(6, 7, 8).

// Check if a value exists in the Slice.
contains := s.Contains(3) // contains is true.

// Find the index of the first element that satisfies a condition.
index, found := s.FindIndex(func(value int) bool {.
    return value > 4.
}).

// Delete an element by index.
s.Delete(2) // Removes the element at index 2.

// Iterate over the elements and perform an operation on each.
s.Each(func(i int, value int) {.
    fmt.Printf("Element %d: %d\n", i, value).
}).

This type provides a set of methods for common Slice operations and is designed to be generic for flexibility.

func New ΒΆ added in v1.2.0

func New[T any](values ...T) *Slice[T]

New creates a new instance of the Slice[T] type and initializes it with the provided values. It allows you to create a new Slice and populate it with the specified elements.

Example:.

s := New[int](1, 2, 3, 4, 5).
// 's' will be a pointer to a new Slice containing [1, 2, 3, 4, 5].
Example ΒΆ
package main

import (
	"fmt"

	"github.com/lindsaygelle/slice"
)

func main() {
	// Create a new Slice
	s := slice.New(1, 2, 3, 4, 5)

	// Append values to the Slice
	s.Append(6, 7, 8)
	fmt.Println("Appended:", s)

	// Append values based on a custom condition
	s.AppendFunc(func(i int, value int) bool {
		return value%2 == 0
	}, 10, 11, 12)
	fmt.Println("Appended based on condition:", s)

	// Get the length of the Slice
	fmt.Println("Length of Slice:", s.Length())

	// Check if the Slice contains a specific value
	fmt.Println("Contains 3:", s.Contains(3)) // Should print true
	fmt.Println("Contains 9:", s.Contains(9)) // Should print false

	// Create a new Slice of booleans indicating if values are present in the original Slice
	contains := s.ContainsMany(2, 5, 8, 10)
	fmt.Println("Contains:", contains)

	// Delete an element at a specific index
	s.Delete(2)
	fmt.Println("Deleted at index 2:", s)

	// Iterate over the Slice and apply a function to each element
	s.Each(func(i int, value int) {
		fmt.Printf("Index %d: %d\n", i, value)
	})

	// Find the index of an element that satisfies a condition
	index, found := s.FindIndex(func(value int) bool {
		return value == 4
	})
	if found {
		fmt.Println("Index of 4:", index) // Should print 3
	} else {
		fmt.Println("4 not found")
	}

	// Get an element at a specific index
	value, ok := s.Get(1)
	if ok {
		fmt.Println("Value at index 1:", value) // Should print 2
	} else {
		fmt.Println("Index 1 not found")
	}

	// Make a new Slice with specific values
	s = s.MakeEach(5, 4, 3, 2, 1)
	fmt.Println("New Slice:", s)

	// Reverse the Slice
	s.Reverse()
	fmt.Println("Reversed Slice:", s)

	// Shuffle the Slice
	s.Shuffle()
	fmt.Println("Shuffled Slice:", s)

	// Slice the Slice from index 2 to 5 (exclusive)
	s.Slice(2, 5)
	fmt.Println("Sliced Slice:", s)

}
Output:

func (*Slice[T]) Append ΒΆ

func (slice *Slice[T]) Append(values ...T) *Slice[T]

Append appends the specified values to the end of the Slice and returns a pointer to the modified Slice. It extends the Slice by adding the provided values to the end, updating the Slice in place.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
s.Append(4, 5) // s is now [1, 2, 3, 4, 5].

func (*Slice[T]) AppendFunc ΒΆ added in v1.1.0

func (slice *Slice[T]) AppendFunc(fn func(i int, value T) bool, values ...T) *Slice[T]

AppendFunc appends selected elements to the end of the Slice based on a provided condition. It iterates over the specified values, invoking the provided function for each element. If the function returns true for an element, that element is added to the end of the Slice.

Example:.

s := &slice.Slice[int]{}.
s.AppendFunc(func(i int, value int) bool {.
  return value%2 == 0 // Append even numbers to the Slice.
}, 1, 2, 3, 4, 5).

After this operation, s will contain [2, 4].

This method modifies the original Slice and returns a pointer to the modified Slice.

func (*Slice[T]) AppendLength ΒΆ

func (slice *Slice[T]) AppendLength(values ...T) int

AppendLength appends the specified values to the end of the Slice and returns the length of the modified Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
length := s.AppendLength(4, 5) // s is now [1, 2, 3, 4, 5], length is 5.

func (*Slice[T]) Bounds ΒΆ

func (slice *Slice[T]) Bounds(i int) bool

Bounds checks if the given integer index is within the valid range of indices for the Slice. It returns true if the index is greater than or equal to 0 and less than the length of the slice, indicating that the index is within bounds.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
inBounds := s.Bounds(1) // inBounds is true.
outOfBounds := s.Bounds(5) // outOfBounds is false.

func (*Slice[T]) Clone ΒΆ added in v1.3.0

func (slice *Slice[T]) Clone() *Slice[T]

Clone creates and returns a new slice that contains the same elements as the original slice. The original slice remains unchanged.

Example:.

numbers := slice.Slice[int]{1, 2, 3, 4, 5}.
clonedSlice := numbers.Clone().
// clonedSlice: [1, 2, 3, 4, 5].

func (*Slice[T]) Concatenate ΒΆ

func (slice *Slice[T]) Concatenate(s *Slice[T]) *Slice[T]

Concatenate merges the elements from the argument Slice to the tail of the receiver Slice and returns the modified Slice. If the provided Slice (s) is not nil, it appends its elements to the end of the receiver slice, updating the Slice in place.

Example:.

s1 := &slice.Slice[int]{1, 2, 3}.
s2 := &slice.Slice[int]{4, 5}.
s1.Concatenate(s2) // s1 is now [1, 2, 3, 4, 5].

func (*Slice[T]) ConcatenateFunc ΒΆ added in v1.1.0

func (slice *Slice[T]) ConcatenateFunc(s *Slice[T], fn func(i int, value T) bool) *Slice[T]

ConcatenateFunc appends elements from the provided Slice (s) to the end of the receiver slice, based on the result of a filtering function.

Example:.

s1 := &slice.Slice[int]{1, 2, 3}.
s2 := &slice.Slice[int]{4, 5, 6}.
s1.ConcatenateFunc(s2, func(i int, value int) bool {.
    return value%2 == 0.
}) // s1 is now [1, 2, 3, 4, 6].

func (*Slice[T]) ConcatenateLength ΒΆ

func (slice *Slice[T]) ConcatenateLength(s *Slice[T]) int

ConcatenateLength merges the elements from the argument Slice to the tail of the receiver Slice and returns the length of the modified Slice.

Example:.

s1 := &slice.Slice[int]{1, 2, 3}.
s2 := &slice.Slice[int]{4, 5}.
length := s1.ConcatenateLength(s2) // s1 is now [1, 2, 3, 4, 5], length is 5.

func (*Slice[T]) Contains ΒΆ

func (slice *Slice[T]) Contains(value T) bool

Contains iterates over the elements of the Slice and compares each element with the provided value. If a matching element is found, it returns true; otherwise, it returns false.

Example:.

s := &slice.Slice[string]{"apple", "banana", "cherry"}.
containsBanana := s.Contains("banana") // containsBanana is true.

func (*Slice[T]) ContainsMany ΒΆ added in v1.1.0

func (slice *Slice[T]) ContainsMany(values ...T) *Slice[bool]

ContainsMany checks if multiple values exist in the Slice and returns a boolean Slice indicating their presence. It takes a variadic number of values and checks each of them against the elements in the Slice. The returned boolean Slice will have 'true' at the corresponding index if the value is found, 'false' otherwise.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
result := s.ContainsMany(2, 4, 6) // result will be [true, true, false].

func (*Slice[T]) Delete ΒΆ

func (slice *Slice[T]) Delete(i int) *Slice[T]

Delete removes the element at the specified index from the slice, if the index is within bounds. It modifies the Slice in place by removing the element at the given index and returns a pointer to the modified Slice. If the index is out of bounds, it does not modify the Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
s.Delete(2) // s is now [1, 2, 4, 5].

func (*Slice[T]) DeleteFunc ΒΆ added in v1.2.0

func (slice *Slice[T]) DeleteFunc(fn func(i int, value T) bool) *Slice[T]

DeleteFunc removes elements from the Slice based on the provided predicate function. It iterates over each element of the Slice and applies the given function to each element. If the function returns true for an element, that element is removed from the slice.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
even := func(i int, value int) bool { return value%2 == 0 }.
s.DeleteFunc(even).
// 's' will contain [1, 3, 5] after removing even elements.

func (*Slice[T]) DeleteLength ΒΆ

func (slice *Slice[T]) DeleteLength(i int) int

DeleteLength removes the element at the specified index from the slice, if the index is within bounds, and returns the new length of the modified Slice. It modifies the Slice in place by removing the element at the given index and returns the new length of the Slice. If the index is out of bounds, it does not modify the Slice and returns the current length.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
newLength := s.DeleteLength(2) // s is now [1, 2, 4, 5], newLength is 4.

func (*Slice[T]) DeleteOK ΒΆ

func (slice *Slice[T]) DeleteOK(i int) bool

DeleteOK removes the element at the specified index from the Slice if the index is within bounds and returns the result of the transaction. It modifies the Slice in place by removing the element at the given index and returns true if the deletion was successful. If the index is out of bounds, it does not modify the Slice and returns false.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
deleted := s.DeleteOK(2) // s is now [1, 2, 4, 5], deleted is true.

func (*Slice[T]) DeleteUnsafe ΒΆ added in v1.2.1

func (slice *Slice[T]) DeleteUnsafe(i int) *Slice[T]

DeleteUnsafe deletes the element from the specified index without bounds checking. It removes the element at the given index without checking whether the index is within the bounds of the slice. Be cautious when using this method to avoid index out-of-range errors.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
s.DeleteUnsafe(2).
// The Slice becomes [1, 2, 4, 5] with the element at index 2 (value 3) removed.

func (*Slice[T]) Each ΒΆ

func (slice *Slice[T]) Each(fn func(i int, value T)) *Slice[T]

Each executes a provided function once for each element in the Slice and returns the Slice. It iterates over each element of the slice, invoking the provided function for each element, and returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[string]{"apple", "banana", "cherry"}.
s.Each(func(i int, value string) {.
    fmt.Printf("Element %d: %s\n", i, value).
}).

func (*Slice[T]) EachBreak ΒΆ

func (slice *Slice[T]) EachBreak(fn func(i int, value T) bool) *Slice[T]

EachBreak executes a provided function once for each element in the Slice with an optional break when the function returns false. It iterates over each element of the slice, invoking the provided function for each element. If the function returns false, the iteration stops. It returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
s.EachBreak(func(i int, value int) bool {.
    fmt.Printf("Element %d: %d\n", i, value).
    return i < 3 // Stop iteration when i is less than 3.
}).

func (*Slice[T]) EachReverse ΒΆ

func (slice *Slice[T]) EachReverse(fn func(i int, value T)) *Slice[T]

EachReverse executes a provided function once for each element in the reverse order they are stored in the Slice. It iterates over each element of the Slice in reverse order, invoking the provided function for each element, and returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
s.EachReverse(func(i int, value int) {.
    fmt.Printf("Element %d: %d\n", i, value).
}).

func (*Slice[T]) EachReverseBreak ΒΆ

func (slice *Slice[T]) EachReverseBreak(fn func(i int, value T) bool) *Slice[T]

EachReverseBreak executes a provided function once for each element in the reverse order they are stored in the Slice with an optional break when the function returns false. It iterates over each element of the Slice in reverse order, invoking the provided function for each element. If the function returns false, the iteration stops. It returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
s.EachReverseBreak(func(i int, value int) bool {.
    fmt.Printf("Element %d: %d\n", i, value).
    return i > 2 // Stop iteration when i is greater than 2.
}).

func (*Slice[T]) Equal ΒΆ added in v1.2.2

func (slice *Slice[T]) Equal(s *Slice[T]) bool

Equal checks if the current Slice is equal to another Slice by comparing their elements. It returns true if the two slices have the same length and all corresponding elements are deeply equal.

Example:.

s1 := slice.Slice[int]{1, 2, 3}.
s2 := slice.Slice[int]{1, 2, 3}.
equal := s1.Equal(s2) // true.

func (*Slice[T]) EqualFunc ΒΆ added in v1.2.2

func (slice *Slice[T]) EqualFunc(s *Slice[T], fn func(i int, value1, value2 T) bool) bool

EqualFunc checks if the current Slice is equal to another Slice by applying a custom comparison function to their elements. It returns true if the two slices have the same length and the custom comparison function returns true for all corresponding elements.

Example:.

s1 := slice.Slice[int]{1, 2, 3}.
s2 := slice.Slice[int]{2, 4, 6}.
customEqual := func(i int, value1, value2 int) bool {.
    return value1*2 == value2.
}.
equal := s1.EqualFunc(s2, customEqual) // true.

func (*Slice[T]) Fetch ΒΆ

func (slice *Slice[T]) Fetch(i int) T

Fetch retrieves the element held at the specified index in the Slice.

Example:.

s := &slice.Slice[string]{"apple", "banana", "cherry"}.
fruit := s.Fetch(1).
// fruit will be "banana".

func (*Slice[T]) FetchLength ΒΆ

func (slice *Slice[T]) FetchLength(i int) (T, int)

FetchLength retrieves the element held at the specified index in the Slice and the length of the Slice. It returns the element at the specified index and the length of the Slice.

Example:.

s := &slice.Slice[int]{10, 20, 30, 40, 50}.
value, length := s.FetchLength(2).
// value will be 30.
// length will be 5.

func (*Slice[T]) Filter ΒΆ added in v1.2.0

func (slice *Slice[T]) Filter(fn func(i int, value T) bool) *Slice[T]

Filter creates a new Slice containing only the elements that satisfy the given predicate function. It iterates over the elements of the Slice and applies the predicate function to each element. Elements for which the predicate returns true are included in the new Slice, and others are excluded.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
filtered := s.Filter(func(x int) bool {.
	return x%2 == 0 // Keep only even numbers.
}).
// filtered will be &Slice[int]{2, 4}.

func (*Slice[T]) FindIndex ΒΆ

func (slice *Slice[T]) FindIndex(fn func(value T) bool) (int, bool)

FindIndex finds the index of the first element that satisfies the given predicate function. It returns the index of the first matching element and true if found; otherwise, it returns -1 and false.

Example:.

s := &slice.Slice[string]{"apple", "banana", "cherry"}.
index, found := s.FindIndex(func(fruit string) bool {.
    return fruit == "banana".
}).
// index will be 1.
// found will be true.

func (*Slice[T]) Get ΒΆ

func (slice *Slice[T]) Get(i int) (T, bool)

Get retrieves the element held at the specified index in the Slice and a boolean indicating if it was successfully retrieved. It returns the element at the specified index and a boolean indicating whether the element was successfully retrieved.

Example:.

s := &slice.Slice[float64]{3.14, 2.71, 1.61}.
value, ok := s.Get(1).
// value will be 2.71.
// ok will be true.

func (*Slice[T]) GetLength ΒΆ

func (slice *Slice[T]) GetLength(i int) (T, int, bool)

GetLength retrieves the element held at the specified index in the slice, the length of the slice, and a boolean indicating if it was successfully retrieved. It returns the element at the specified index, the length of the slice, and a boolean indicating whether the element was successfully retrieved.

Example:.

s := &slice.Slice[int]{10, 20, 30, 40, 50}.
value, length, ok := s.GetLength(2).
// value will be 30.
// length will be 5.
// ok will be true.

func (*Slice[T]) IsEmpty ΒΆ

func (slice *Slice[T]) IsEmpty() bool

IsEmpty returns whether the Slice is empty. It returns true if the Slice is empty (length is zero), otherwise false.

Example:.

s := &slice.Slice[int]{}.
isEmpty := s.IsEmpty() // isEmpty will be true.

func (*Slice[T]) IsPopulated ΒΆ added in v1.1.0

func (slice *Slice[T]) IsPopulated() bool

IsPopulated returns whether the Slice is populated. It returns true if the Slice is not empty (length is greater than zero), otherwise false.

Example:.

s := &slice.Slice[int]{10, 20, 30}.
isPopulated := s.IsPopulated() // isPopulated will be true.

func (*Slice[T]) Length ΒΆ

func (slice *Slice[T]) Length() int

Length returns the number of elements in the Slice.

Example:.

s := &slice.Slice[int]{10, 20, 30, 40, 50}.
length := s.Length() // length will be 5.

func (*Slice[T]) Make ΒΆ

func (slice *Slice[T]) Make(i int) *Slice[T]

Make empties the slice, sets the new Slice to the length of n, and returns the modified Slice. It replaces the existing Slice with a new Slice of the specified length (n) and returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{10, 20, 30}.
s.Make(3) // s will be an empty Slice of length 3.

func (*Slice[T]) MakeEach ΒΆ

func (slice *Slice[T]) MakeEach(v ...T) *Slice[T]

MakeEach empties the slice, sets the new Slice to the length of n, and populates it by performing a for-each loop on the provided values. Finally, it returns a pointer to the modified Slice. It replaces the existing Slice with a new Slice of the specified length (n) and populates it by performing a for-each loop on the provided values.

Example:.

s := &slice.Slice[int]{}.
s.MakeEach(10, 20, 30) // s will be a Slice containing {10, 20, 30}.

func (*Slice[T]) MakeEachReverse ΒΆ

func (slice *Slice[T]) MakeEachReverse(values ...T) *Slice[T]

MakeEachReverse empties the slice, sets the new Slice to the length of n, and performs an inverse for-each loop on the provided values,. inserting each entry at the appropriate index before returning the modified Slice. It replaces the existing Slice with a new Slice of the specified length (n) and populates it by performing an inverse for-each loop on the provided values.

Example:.

s := &slice.Slice[int]{}.
s.MakeEachReverse(10, 20, 30) // s will be a Slice containing {30, 20, 10}.

func (*Slice[T]) Map ΒΆ

func (slice *Slice[T]) Map(fn func(i int, value T) T) *Slice[T]

Map applies the provided function to each element in the slice and creates a new slice containing the modified elements. It returns a new Slice[T] containing the transformed elements. The original slice is not modified.

Example:.

numbers := slice.Slice[int]{1, 2, 3, 4, 5}.
squared := numbers.Map(func(i int, value int) int {.
    return value * value.
}).
// squared: [1, 4, 9, 16, 25].

func (*Slice[T]) MapReverse ΒΆ added in v1.1.0

func (slice *Slice[T]) MapReverse(fn func(i int, value T) T) *Slice[T]

MapReverse applies the provided function to each element in the slice in reverse order and creates a new slice containing the modified elements. It returns a new Slice[T] containing the transformed elements. The original slice is not modified.

Example:.

numbers := slice.Slice[int]{1, 2, 3, 4, 5}.
reversedSquared := numbers.MapReverse(func(i int, value int) int {.
    return value * value.
}).
// reversedSquared: [25, 16, 9, 4, 1].

func (*Slice[T]) Modify ΒΆ added in v1.3.0

func (slice *Slice[T]) Modify(fn func(i int, value T) T) *Slice[T]

Modify applies the provided function to each element in the slice and modifies the elements in place. It iterates over the slice, applying the function to each element along with its index, and replaces the element with the result.

Example:.

numbers := slice.Slice[int]{1, 2, 3, 4, 5}.
modifiedSlice := numbers.Modify(func(i int, value int) int {.
    return value * 2.
}).
// modifiedSlice: [2, 4, 6, 8, 10].

func (*Slice[T]) Poll ΒΆ

func (slice *Slice[T]) Poll() T

Poll removes the first element from the Slice and returns that removed element. It removes and returns the first element of the Slice if the Slice is not empty.

Example:.

s := &slice.Slice[int]{10, 20, 30}.
value := s.Poll() // value will be 10, and s will be [20, 30].

func (*Slice[T]) PollLength ΒΆ

func (slice *Slice[T]) PollLength() (T, int)

PollLength removes the first element from the Slice and returns the removed element and the length of the modified Slice. It removes and returns the first element of the Slice along with the new length of the modified Slice if the Slice is not empty.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
value, length := s.PollLength() // value will be 1, and length will be 2.

func (*Slice[T]) PollOK ΒΆ

func (slice *Slice[T]) PollOK() (T, bool)

PollOK removes and returns the first element from the Slice if it is not empty. It checks whether the Slice is populated (not empty) and removes the first element. If the Slice is populated, it returns the removed element along with true; otherwise, it returns the zero value for the element and false.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
value, ok := s.PollOK().
// 'value' will be 1, and 'ok' will be true as the Slice is not empty.

func (*Slice[T]) Pop ΒΆ

func (slice *Slice[T]) Pop() T

Pop removes and returns the last element from the Slice if it is not empty. It checks whether the Slice is populated (not empty) and removes the last element. If the Slice is populated, it returns the removed element; otherwise, it returns the zero value for the element.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
value := s.Pop().
// 'value' will be 3, and the Slice will become [1, 2].

func (*Slice[T]) PopLength ΒΆ

func (slice *Slice[T]) PopLength() (T, int)

PopLength removes the last element from the Slice and returns the removed element along with the length of the modified Slice. It removes and returns the last element of the Slice if the Slice is not empty, along with the new length of the modified Slice.

Example:.

s := &slice.Slice[int]{10, 20, 30}.
value, length := s.PopLength() // value will be 30, length will be 2, and s will be [10, 20].

func (*Slice[T]) PopOK ΒΆ

func (slice *Slice[T]) PopOK() (T, bool)

PopOK removes the last element from the Slice and returns a boolean indicating the outcome of the transaction. It removes the last element from the Slice and returns true if the Slice is not empty; otherwise, it returns false.

Example:.

s := &slice.Slice[int]{10, 20, 30}.
value, ok := s.PopOK() // value will be 30, ok will be true, and s will be [10, 20].

func (*Slice[T]) Precatenate ΒΆ

func (slice *Slice[T]) Precatenate(s *Slice[T]) *Slice[T]

Precatenate merges the elements from the argument Slice to the head of the receiver Slice and returns the modified Slice. If the provided Slice (s) is not nil, it prepends its elements to the receiver Slice and returns a pointer to the modified Slice.

Example:.

s1 := &slice.Slice[int]{1, 2, 3}.
s2 := &slice.Slice[int]{4, 5}.
s1.Precatenate(s2) // s1 will be [4, 5, 1, 2, 3].

func (*Slice[T]) PrecatenateFunc ΒΆ added in v1.1.0

func (slice *Slice[T]) PrecatenateFunc(s *Slice[T], fn func(i int, value T) bool) *Slice[T]

PrecatenateFunc prepends elements from another Slice to the head of the receiver Slice based on a provided predicate function. It iterates over each element in the source slice, invoking the provided function. If the function returns 'true' for an element,. that element is prepended to the receiver slice. If it returns 'false', the element is skipped.

Example:.

s1 := &slice.Slice[int]{1, 2, 3}.
s2 := &slice.Slice[int]{4, 5, 6}.
result := s1.PrecatenateFunc(s2, func(i int, value int) bool {.
    return value%2 == 0.
}) // s1 will be modified to [4, 6, 2, 1, 3], and 'result' will be a pointer to 's1'.

func (*Slice[T]) PrecatenateLength ΒΆ

func (slice *Slice[T]) PrecatenateLength(s *Slice[T]) int

PrecatenateLength merges the elements from the argument Slice to the head of the receiver Slice and returns the length of the modified Slice. If the provided Slice (s) is not nil, it prepends its elements to the receiver Slice and returns the length of the modified Slice.

Example:.

s1 := &slice.Slice[int]{1, 2, 3}.
s2 := &slice.Slice[int]{4, 5}.
length := s1.PrecatenateLength(s2) // length will be 5, and s1 will be [4, 5, 1, 2, 3].

func (*Slice[T]) Prepend ΒΆ

func (slice *Slice[T]) Prepend(values ...T) *Slice[T]

Prepend adds one element to the head of the Slice and returns the modified Slice. It adds the specified values to the beginning of the existing Slice and returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{2, 3}.
s.Prepend(1) // s will be [1, 2, 3].

func (*Slice[T]) PrependFunc ΒΆ added in v1.1.0

func (slice *Slice[T]) PrependFunc(fn func(i int, value T) bool, values ...T) *Slice[T]

PrependFunc prepends elements to the head of the receiver Slice based on a provided predicate function. It iterates over each element in the 'values' argument, invoking the provided function. If the function returns 'true' for an element,. that element is prepended to the receiver slice. If it returns 'false', the element is skipped.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
result := s.PrependFunc(func(i int, value int) bool {.
    return value%2 == 0.
}, 4, 5, 6) // 's' will be modified to [6, 4, 2, 1, 3], and 'result' will be a pointer to 's'.

func (*Slice[T]) PrependLength ΒΆ

func (slice *Slice[T]) PrependLength(values ...T) int

PrependLength adds n elements to the head of the Slice and returns the length of the modified Slice. It adds the specified values to the beginning of the existing Slice and returns the length of the modified Slice.

Example:.

s := &slice.Slice[int]{2, 3}.
length := s.PrependLength(1, 0) // length will be 4, and s will be [1, 0, 2, 3].

func (*Slice[T]) Reduce ΒΆ added in v1.1.0

func (slice *Slice[T]) Reduce(fn func(i int, currentValue T, resultValue T) T) T

Reduce applies the provided function to each element in the slice and reduces the elements to a single value. It iterates over the slice, applying the function to each element along with its index and the current result value,. and accumulates the result. The result of the previous function call is passed as the third argument to the next function call. It returns the final reduced value.

Example:.

numbers := slice.Slice[int]({1, 2, 3, 4, 5}).
sum := numbers.Reduce(func(i int, currentValue int, resultValue int) int {.
    return resultValue + currentValue.
}).
// sum: 15 (1 + 2 + 3 + 4 + 5).

func (*Slice[T]) ReduceReverse ΒΆ added in v1.3.0

func (slice *Slice[T]) ReduceReverse(fn func(i int, currentValue T, resultValue T) T) T

ReduceReverse iterates over the slice in reverse order and reduces the elements into a single value using the provided function. It starts from the last element and accumulates the result by applying the function to each element along with its index and the current accumulated result. The result of each iteration becomes the input for the next iteration.

Example:.

numbers := slice.Slice[int]{1, 2, 3, 4, 5}.
sum := numbers.ReduceReverse(func(i int, currentValue, resultValue int) int {.
    return currentValue + resultValue.
}).
// sum: 15 (sum of all elements in the slice).

func (*Slice[T]) Replace ΒΆ

func (slice *Slice[T]) Replace(i int, value T) bool

Replace changes the contents of the Slice at the argument index if it is in bounds. It replaces the element at the specified index with the provided value if the index is within bounds and returns true. Otherwise, it returns false.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
ok := s.Replace(1, 4) // ok will be true, and s will be [1, 4, 3].

func (*Slice[T]) Reverse ΒΆ

func (slice *Slice[T]) Reverse() *Slice[T]

Reverse reverses the Slice in linear time and returns the modified Slice. It reverses the order of elements in the Slice and returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
s.Reverse() // s will be [3, 2, 1].

func (*Slice[T]) Set ΒΆ

func (slice *Slice[T]) Set() *Slice[T]

Set returns a unique slice, removing duplicate elements that have the same hash value. Returns the modified Slice at the end of the iteration. It removes duplicate elements from the slice, keeping only the first occurrence of each unique element. Returns a pointer to the modified Slice with unique elements.

Example:.

s := &slice.Slice[int]{1, 2, 2, 3, 3, 3}.
s.Set() // s will be [1, 2, 3].

func (*Slice[T]) Shuffle ΒΆ added in v1.2.0

func (slice *Slice[T]) Shuffle() *Slice[T]

Shuffle randomly shuffles the elements of the Slice and returns the modified Slice. It shuffles the elements of the Slice in a random order and returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
s.Shuffle() // s will be a random permutation of [1, 2, 3, 4, 5].

func (*Slice[T]) Slice ΒΆ

func (slice *Slice[T]) Slice(i int, j int) *Slice[T]

Slice slices the Slice from i to j and returns a new Slice. It slices the Slice from the specified start (i) index to the end (j) index (inclusive),. and returns a pointer to the new Slice.

Example:.

numbers := slice.Slice[int]{1, 2, 3, 4, 5}.
// Create a new slice containing elements at indexes 1 to 3 from the original slice.
subset := numbers.Slice(1, 4).
// Resulting subset: [2, 3, 4].

func (*Slice[T]) SortFunc ΒΆ added in v1.2.2

func (slice *Slice[T]) SortFunc(fn func(i int, j int, a T, b T) bool) *Slice[T]

SortFunc sorts the elements of the slice based on a custom comparison function. Takes a comparison function that takes two indices (i, j) and two elements (a, b) of type T and returns true if element a should come before element b in the sorted order. If fn returns true, it means a is considered less than b in the sorting order.

s := &slice.Slice[int]{5, 2, 8, 1, 9}.
s.SortFunc(func(i, j int, a, b int) bool {.
    return a < b.
}).

func (*Slice[T]) Splice ΒΆ added in v1.3.0

func (slice *Slice[T]) Splice(i int, j int) *Slice[T]

Splice slices the Slice from i to j and returns the modified Slice. It slices the Slice from the specified start (i) index to the end (j) index (inclusive),. and returns a pointer to the modified Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3, 4, 5}.
s.Splice(1, 3) // s will be [2, 3, 4].

func (*Slice[T]) Swap ΒΆ

func (slice *Slice[T]) Swap(i int, j int)

Swap moves element i to j and j to i. If both indices (i and j) are within bounds, it swaps the elements at those positions in the Slice.

Example:.

s := &slice.Slice[int]{1, 2, 3}.
s.Swap(0, 2) // s will be [3, 2, 1].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL