[READ-ONLY] Mirror of https://github.com/andrioid/humle. Write HTML with Go functions
0

Configure Feed

Select the types of activity you want to include in your feed.

humle / helpers.go
522 B 31 lines
1package humle 2 3func Iterate[T any](ts []T, cb func(int, T) Node) Group { 4 nodes := make([]Node, 0, len(ts)) 5 for i, t := range ts { 6 nodes = append(nodes, cb(i, t)) 7 } 8 return nodes 9} 10 11func If(condition bool, n Node) Node { 12 if condition { 13 return n 14 } 15 return nil 16} 17 18func Iff(condition bool, f func() Node) Node { 19 if condition { 20 return f() 21 } 22 return nil 23} 24 25func Map[T any](ts []T, cb func(T) Node) Group { 26 nodes := make([]Node, 0, len(ts)) 27 for _, t := range ts { 28 nodes = append(nodes, cb(t)) 29 } 30 return nodes 31}