Zen
Zen is an utility-first package that provides a set of commonly used functions, helpers and extensions.
Most of the functions are adapted to be used with html/template
.
Motivation
We had too many cases of copy-pasting the same code between projects over and over again.
So I decided to combine it all in one place.
Documentation
Code is well-documented, so it's pretty comfortable to use documentation provided by pkg.go.dev
Examples
Provided examples doesn't cover all the features of the library. Please refer to the documentation for details.
package main
import (
"time"
"git.sr.ht/~kyoto-framework/zen"
)
func foo() zen.Future[string] {
return zen.Async(func() (string, error) {
time.Sleep(time.Second)
return "bar", nil
})
}
func main() {
slice := zen.Range(1, 5)
zen.Min(slice)
zen.Max(slice)
zen.Avg(slice)
zen.Filter(slice, func(v int) bool { return v < 3 })
zen.Map(slice, func(v int) int { return v * 2 })
zen.In(1, slice)
zen.Pop(slice, 1)
zen.Insert(slice, 1, 2)
zen.Last(slice)
zen.Any(slice, func(v int) bool { return v == 2 })
zen.All(slice, func(v int) bool { return v < 6 })
zen.Ptr(1)
zen.Bool(3)
zen.Int("5")
zen.Float64("6.5")
zen.String(7)
zen.Compose("foo", 1, "bar", "2")
zen.Must(strconv.Atoi("1"))
futureFoo := foo()
println("foo call is not blocked")
result, _ := zen.Await(futureFoo)
println(result)
}