package main
import (
"fmt"
"iter"
"maps"
"slices"
)
const numberOfDaysInWeek = 7
const (
Monday = "Monday"
Tuesday = "Tuesday"
Wednesday = "Wednesday"
Thursday = "Thursday"
Friday = "Friday"
Saturday = "Saturday"
Sunday = "Sunday"
First = "1st"
Second = "2nd"
Third = "3rd"
Fourth = "4th"
Fifth = "5th"
Sixth = "6th"
Last = "Last"
)
type Root struct {
showForILoop bool
showKVLoop bool
showShortCutLoop bool
showSortedLoop bool
showIteratorLoop bool
daysInWeek [numberOfDaysInWeek]string
daysInWeekIth map[string]string
}
func (c *Root) Init() {
c.daysInWeek = [numberOfDaysInWeek]string{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
c.daysInWeekIth = map[string]string{First: Monday, Second: Tuesday, Third: Wednesday, Fourth: Thursday, Fifth: Friday, Sixth: Saturday, Last: Sunday}
}
func (c *Root) ToggleForILoop() bool {
c.showForILoop = !c.showForILoop
return c.showForILoop
}
func (c *Root) ShowForILoop() bool {
return c.showForILoop
}
func (c *Root) DaysInWeek() int {
return numberOfDaysInWeek
}
func (c *Root) DayOfWeek(i int) string {
return c.daysInWeek[i]
}
func (c *Root) ToggleKVLoop() bool {
c.showKVLoop = !c.showKVLoop
return c.showForILoop
}
func (c *Root) ShowKVLoop() bool {
return c.showKVLoop
}
func (c *Root) DaysInWeekIth() map[string]string {
return c.daysInWeekIth
}
func (c *Root) ToggleShortCutLoop() bool {
c.showShortCutLoop = !c.showShortCutLoop
return c.showShortCutLoop
}
func (c *Root) ShowShortCutLoop() bool {
return c.showShortCutLoop
}
func (c *Root) ToggleSortedLoop() bool {
c.showSortedLoop = !c.showSortedLoop
return c.showSortedLoop
}
func (c *Root) ShowSortedLoop() bool {
return c.showSortedLoop
}
func (c *Root) DaysInWeekIthSorted() []string {
return slices.Sorted(maps.Keys(c.daysInWeekIth))
}
func (c *Root) ToggleIteratorLoop() bool {
c.showIteratorLoop = !c.showIteratorLoop
return c.showIteratorLoop
}
func (c *Root) ShowIteratorLoop() bool {
return c.showIteratorLoop
}
func (c *Root) DaysInWeekIterator() iter.Seq2[int, string] {
return func(yield func(int, string) bool) {
for i, v := range c.daysInWeek {
fmt.Printf("i: %d, v:%s\n", i, v)
if !yield(i, v) {
return
}
}
}
}