merger

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package merger provides utilities for merging slices of strings.

This package is designed to handle various scenarios where multiple slices of strings need to be combined into a single slice. It ensures that nil slices are skipped and empty slices are handled gracefully, resulting in a merged slice that contains all the elements from the input slices in the order they were provided.

The primary function in this package is MergeSlices, which takes multiple slices of strings as input and returns a single merged slice. This function is useful in scenarios where you need to consolidate data from different sources or collections of strings.

Example usage:

// Import the merger package
import "path/to/merger"

// Define multiple slices of strings
slice1 := []string{"a", "b"}
slice2 := []string{"c", "d"}
slice3 := []string{"e", "f"}

// Merge the slices
merged := merger.MergeSlices(slice1, slice2, slice3)
// merged now contains: ["a", "b", "c", "d", "e", "f"]

// Merge slices with nil and empty slices
slice4 := []string{"g", "h"}
emptySlice := []string{}

merged = merger.MergeSlices(nil, slice1, emptySlice, slice4)
// merged now contains: ["a", "b", "g", "h"]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeSlices

func MergeSlices(slices ...[]string) []string

MergeSlices merges multiple slices of strings into a single slice. It skips any nil slices and handles empty slices gracefully.

Parameters:

  • slices: A variadic parameter that takes multiple slices of strings.

Returns:

  • A single slice of strings containing all the elements from the input slices, in the order they were provided.

Example:

// Merge multiple slices of strings
slice1 := []string{"a", "b"}
slice2 := []string{"c", "d"}
slice3 := []string{"e", "f"}

merged := MergeSlices(slice1, slice2, slice3)
// merged now contains: ["a", "b", "c", "d", "e", "f"]

// Merge slices with nil and empty slices
slice4 := []string{"g", "h"}
emptySlice := []string{}

merged = MergeSlices(nil, slice1, emptySlice, slice4)
// merged now contains: ["a", "b", "g", "h"]

Types

This section is empty.

Jump to

Keyboard shortcuts

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