jaeyeom / gogo Goto Github PK
View Code? Open in Web Editor NEWExample code for go.
License: MIT License
Example code for go.
License: MIT License
라고 설명해주셨는데, 콜백을 이용해서 어떻게 구현해야할지 모르겠습니다.
클로저를 이용하려면 함수를 리턴하는 패턴일거고, 리턴 되는 함수와 매칭된 변수들이 있어서 그 변수들을 이용해야 할거라고 예측은 됩니다.
리턴된 함수를 콜 할 때마다 알맞는 결과가 한 번씩 반환되어야 할거라고 생각되는데요.
아래처럼 작성해봤는데, 예쁘지 않아서 마음에 들지 않습니다.
좋은 방법을 알려주세요.
func BabyNamesGenerator(first, second string) func() string {
len_first := len([]rune(first))
len_second := len([]rune(second))
next, i, j := 0, 0, 0
return func() string {
if next == len_first*len_second {
return ""
}
name := string([]rune(first)[i]) + string([]rune(second)[j])
next++
j++
i = j / len_second
j = j % len_second
return name
}
}
func Example_BabyNamesGenerator() {
get_names := BabyNamesGenerator("성정명재경", "준호우훈진")
for name := get_names(); name != ""; name = get_names() {
fmt.Print(name, ",")
}
// Output:
// 성준,성호,성우,성훈,성진,정준,정호,정우,정훈,정진,명준,명호,명우,명훈,명진,재준,재호,재우,재훈,재진,경준,경호,경우,경훈,경진,
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.