超好用的工具库!字符串、整型、对象、数组等的各种操作,如 map, filter, contains, find...
类似于 Nodejs 的 lodash.js (Lodash 简介 | Lodash中文文档 | Lodash中文网) 、Python 内置(builtin.py)的 map、filter 等
包含一系列工具函数如图,探究所需请移步 GitHub 地址:https://github.com/samber/lo
这里以常用的 map 函数举例,如下:
/*
*
工具库 samber/lo 类似于 lodash.js
github地址:https://github.com/samber/lo
author: huang
date: 2023-09-15
File: useSamberlo.go
Description:
*/
package main
import (
"fmt"
lo "github.com/samber/lo"
lop "github.com/samber/lo/parallel"
"strconv"
"strings"
)
func t1() {
res := lop.Map([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
return strconv.FormatInt(x, 10)
})
fmt.Println(res)
// []string{"1", "2", "3", "4"}
}
func main() {
t1()
}