Created
July 26, 2023 13:00
-
-
Save iFurySt/dc2beecf4f491e656cc1c4abed27e2bd to your computer and use it in GitHub Desktop.
Sort a slice with generic type in Go.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/ifuryst/lol" | |
"golang.org/x/exp/slices" | |
"math" | |
) | |
func main() { | |
s := lol.MergeSlice([]float64{5, 1, math.NaN(), 2, 4, math.NaN(), 9}) | |
slices.Sort(s) | |
fmt.Println(s) | |
// Output: | |
// [NaN NaN 1 2 4 5 9] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment