wynn5a / go-stream

Stream api for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-stream

A simple Stream api for Go

Usage

// create
stream := From(1, 2, 3, 4, 5)
// consume
str := stream.Drop(2).Take(2).Join("-")
fmt.Println(str) //3-4

Python generator code

def underscore_to_camelcase(s):
    def camelcase():
        yield str.lower
        while True:
            yield str.capitalize

    return ''.join(f(sub) for sub, f in zip(s.split('_'), camelcase()))

Equivalent

func underscoreToCamelCase(str string) string {
	capitalize := func(s string) string {
		return strings.ToUpper(s[0:1]) + s[1:]
	}

	stream := func(c Consumer[func(string) string]) {
		c(strings.ToLower)
		for {
			c(capitalize)
		}
	}

	return Zip(stream, strings.Split(str, "_"), func(f func(string) string, str string) string {
		return f(str)
	}).Join("")
}

About

Stream api for Go

License:Apache License 2.0


Languages

Language:Go 100.0%