Skip to content
forked from hymkor/go-lazy

lazy initialization for golang

License

Notifications You must be signed in to change notification settings

yulin-li/go-lazy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

lazy

Provides support for lazy initialization by generics in Go1.18

example 1

package main

import (
    "github.com/hymkor/go-lazy"
)

var s1 = lazy.New(func() string {
    println("s1 initialize")
    return "Foo"
})

func main() {
    println(s1.Value())
    println(s1.Value())
}
$ go run example.go
s1 initialize
Foo
Foo

example 2

Same as example 1. Light but long

package main

import (
    "github.com/hymkor/go-lazy"
)

var s1 = lazy.Of[string]{
    New: func() string {
        println("s1 initialize")
        return "Foo"
    },
}

func main() {
    println(s1.Value())
    println(s1.Value())
}

About

lazy initialization for golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%