This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/pkg/util/list.go
SoXX 802764092e refactor_folder_structure_#11 (#14)
As mentioned in Issue #11, the folder structure got an overall as some file names

Co-authored-by: Fenpaws <soxx@fenpa.ws>
Reviewed-on: anthrove/e621-to-graph#14
Reviewed-by: Lennard Brinkhaus <lennard.brinkhaus@noreply.localhost>
Co-authored-by: SoXX <fenpaws@noreply.localhost>
Co-committed-by: SoXX <fenpaws@noreply.localhost>
2023-07-17 10:57:23 +00:00

28 lines
731 B
Go

package util
// UniqueNonEmptyElementsOf returns a new slice containing unique non-empty elements from the input slice.
// It removes duplicate elements and empty strings while preserving the order of appearance.
func UniqueNonEmptyElementsOf(s []string) []string {
// Create a map to store unique elements
unique := make(map[string]bool)
// Create a new slice to store the unique non-empty elements
us := make([]string, 0, len(s))
for _, elem := range s {
// Skip empty strings
if len(elem) == 0 {
continue
}
// Check if the element is already in the unique map
if !unique[elem] {
// Add the element to the unique map and the new slice
unique[elem] = true
us = append(us, elem)
}
}
return us
}