-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGen.go
51 lines (44 loc) · 1 KB
/
Gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package goutility
import (
"bufio"
"fmt"
"log"
"math/rand"
"os"
"strings"
)
// When called takes input and gives a String.
func GetString() func(inpRdr *bufio.Reader) string {
return func(inpRdr *bufio.Reader) string {
word, err := inpRdr.ReadString('\n')
if err != nil {
log.Fatalln(err)
}
return strings.ToLower(strings.TrimSpace(word))
}
}
// When called takes input and gives a Rune.
func GetRune() func(inpRdr *bufio.Reader) rune {
return func(inpRdr *bufio.Reader) rune {
r, _, err := inpRdr.ReadRune()
if err != nil {
log.Fatalln(err)
}
return r
}
}
// Selects a random item from array
func GetRandItem[T any](tp []T) *T {
fmt.Println(len(tp))
c := tp[rand.Intn(len(tp))]
return &c
}
func GetNewRdr(reader *bufio.Reader) *bufio.Reader {
return bufio.NewReader(reader)
}
func GetNewRdrWritr(reader *bufio.Reader, writer *bufio.Writer) *bufio.ReadWriter {
return bufio.NewReadWriter(reader, writer)
}
func GetNewStdInRdr() *bufio.Reader {
return bufio.NewReader(os.Stdin)
}