Underscore.goGO 工具库

联合创作 · 2023-09-28 16:59

Underscore.go 是一个非常有帮助的 Go 实用程序集。类似 underscore.js,但是是 GO 的工具库。


计划功能:



  • godoc


  • contains


  • indexOf


  • worker pools


  • parallel each


  • parallel map with worker pool


  • refactor to make functions first parameter (eg Each func(func(A), []A))


  • handle maps & slices


  • all


  • any


  • none



示例:



import "un"s := []string{"a", "b", "c", "d"}

fn := func(s string) string {
 return s + "!"
}

// Generic, interface based helpers
m:= un.Map(s, fn)
fmt.Println(m) //["a!", "b!", "c!", "d!"]

// Define your own typed functions
var SMap func([]string, func(string) string) []string
un.MakeMap(&SMap)

m := un.SMap(s, fn)
fmt.Println(m) //["a!", "b!", "c!", "d!"]

 

浏览 16
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报