当前位置:   article > 正文

Go 之 工具库 samber/lo_go 类似 lodash的

go 类似 lodash的

 超好用的工具库!字符串、整型、对象、数组等的各种操作,如 map, filter, contains, find...

类似于 Nodejs 的 lodash.js (Lodash 简介 | Lodash中文文档 | Lodash中文网) 、Python 内置(builtin.py)的 map、filter 等

包含一系列工具函数如图,探究所需请移步 GitHub 地址:https://github.com/samber/lo

这里以常用的 map 函数举例,如下:

  1. /*
  2. *
  3. 工具库 samber/lo 类似于 lodash.js
  4. github地址:https://github.com/samber/lo
  5. author: huang
  6. date: 2023-09-15
  7. File: useSamberlo.go
  8. Description:
  9. */
  10. package main
  11. import (
  12. "fmt"
  13. lo "github.com/samber/lo"
  14. lop "github.com/samber/lo/parallel"
  15. "strconv"
  16. "strings"
  17. )
  18. func t1() {
  19. res := lop.Map([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
  20. return strconv.FormatInt(x, 10)
  21. })
  22. fmt.Println(res)
  23. // []string{"1", "2", "3", "4"}
  24. }
  25. func main() {
  26. t1()
  27. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/839262
推荐阅读
相关标签
  

闽ICP备14008679号