go4kids

package module
v0.0.0-...-33a8513 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 9 Imported by: 0

README

Go Helper Library For Kids

This repository contains code that aims to make learning Go programming considerably less painful for children and other beginners. It contains a number of convenience functions and other features that come built-in with simpler languages like Python, and hopefully eases the Golang learning curve a little 🙂.

Go is a wonderful, modern cross-platform language for teaching, is almost as easy to pick up as Python or Ruby, and the elegant simplicity of the syntax makes it a joy to work with. Go is an excellent choice for anyone wishing to gain a better understanding of statically-typed, compiled languages. This repository is currently a work in progress and a companion to my (unfinished) programming book for kids.

Getting started and Installation

To import this library, simply type the following into the terminal:

go get git.paleblue.cloud/mark/go4kids

To use it in your code, add the following to the top of your Go file(s), and use it like so:

package main

import (
	"fmt"

	g4k "git.paleblue.cloud/mark/go4kids"
)

func main() {
	greeting := "Hello everyone! I am learning Go!"
	fmt.Println(g4k.ReverseString(greeting))
}
!oG gninrael ma I !enoyreve olleH

Try it


Support

For help, support or suggestions, feel free to shoot me an email at mark@paleblue.cloud. This is a personal project, but I'm open to suggestions for improvement :)

Roadmap

  • Implement basic functions to help the youngsters begin their Go journey.

  • Implement some more complex functions and other data structures to avoid re-inventing the wheel.

  • TODO

Contributing

This is a personal project that is probably of little interest to anyone yet, but suggestions for improvement are always welcome.

Licenses

All source code is released under The MIT License, and any other original materials are licensed under the Creative Commons BY-NC 4.0. Other resources contained in this document and any web-pages and/or information linked to remain the intellectual property of the original authors. Information copied or adapted from these sources is used under the terms of their respective licences, and I have attempted to adhere to the principles of acceptable use where any ambiguity exists.

I have given full credit to all original authors wherever possible, and encourage the reader to browse the original sources of any or all of the information included. These source materials contain a wealth of fascinating in-depth information, explained far better than I could ever hope to achieve.

Disclaimer

I take full responsibility for any inaccuracies, misunderstandings, misinterpretations, omissions, and plain old stupidity contained within my code or the book. I take great delight in writing about the fascinating world of technology, but sadly the world always finds ways to make an idiot of me. If anything seems wrong, correct me via email, and check the great sources in the next section.


Resources

Websites
  1. Official Go Documentation, the Standard Library reference, and the Go FAQ.

  2. The Go Blog also has some wonderfully in-depth articles on Go's inner workings. For example, this article on the internal magic of slices and arrays, this one on how strings and runes work underneath, or this one on how maps work internally. It may sound boring, but is vital knowledge if you want to be a better programmer.

  3. DevDocs (Much like the Standard Library reference above, but much faster and easier to read. It's not just Go either, it has everything)

  4. Effective Go

  5. Go By Example (Excellent resource for when you just want answers now)

  6. Go Web Examples (Very good web-focused tutorials)

  7. Golang Programs

  8. Golang By Example

  9. Golang Docs

  10. Calhoun.io and Gophercises

  11. A Tour of Go

  12. GolangBot

  13. The Go Forum

  14. GoSamples

  15. Golang Code

  16. Awesome Go (A curated list of Go frameworks, libraries, and software)

  17. Golang News

  18. Golang Weekly (Weekly Go newsletter sent to your email)

  19. Awesome Go Weekly (Another weekly Go newsletter)

  20. Applied Go

Free (or free-ish) Books

Note: Although some free Go books are a little older, Go has a conservative approach to language changes and is committed to backwards-compatibility. Aside from updates to best-practices, little has changed in the past decade, and 99% of the principles are still valid.

  1. Go 101, and its GitHub repository: Excellent and up-to-date book that can even be installed and read offline with go install go101.org/go101@latest, then go101 to start the web server.

  2. Go, From the Beginning (Up-to-date, very thorough)

  3. Practical Go Lessons (Up-to-date, free web version)

  4. How to Code in Go (Fantastic tutorial series by DigitalOcean. Web, PDF or EPUB, but web is best)

  5. The Web-Dev-Golang-Anti-Textbook, and its GitHub repository. Excellent book about Go web development.

  6. The Little Go Book

  7. An Introduction to Programming in Go

  8. Go Bootcamp

  9. Learning Go

  10. Go for JavaScript Developers

Free Videos
  1. Learn Go Programming - Golang Tutorial for Beginners (freeCodeCamp, 7 hours)

  2. Learn Go Programming by Building 11 Projects – Full Course (freeCodeCamp, 8.5 hours)

  3. Golang Tutorial for Beginners | Full Go Course (YouTube, ~3.5 hours)

  4. Golang Dojo (YouTube channel)

  5. Golang Tutorial : Go Full Course (Derek Banas, ~3.5 Hours)

  6. Go / Golang Crash Course (Traversy Media, ~1.5 hours)

  1. Go Bootcamp: Master Golang with 1000+ Exercises and Projects

  2. Go (Golang) Programming: The Complete Go Bootcamp 2023

Tools
  1. Go Playground (Run Go in the browser and try out code)

  2. Better Go Playground (As above, but much nicer)

  3. JSON-To-Go (Converts JSON to Go structs automatically, also available as a VS Code extension. You'll thank me later 😏)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](s []T, f func(T) bool) bool

All is a function that checks if all items in a slice satisfy a given condition and returns true or false accordingly.

func Any

func Any[T any](s []T, f func(T) bool) bool

Any is a function that checks if any of the items in a slice satisfy a given condition and returns true or false accordingly.

func Contains

func Contains[T comparable](s []T, item T) bool

Contains is a function that checks if a slice contains a given item and returns a boolean.

func ContainsAny

func ContainsAny[T comparable](s []T, items ...T) bool

ContainsAny is a function that checks if a slice contains any of a given set of items and returns a boolean.

func Deduplicate

func Deduplicate[T comparable](s []T) []T

Deduplicate removes duplicate elements from a slice and returns the result.

func Filter

func Filter[T any](s []T, f func(T) bool) []T

Filter is a function that filters a slice by a given condition and returns the resulting slice.

func Input

func Input(prompt string) string

Input is a function that prompts the user for input and returns the input as a string.

func IsDir

func IsDir(path string) bool

IsDir is a function that returns true if the path exists and is a directory.

func IsExecutable

func IsExecutable(path string) bool

IsExecutable is a function that returns true if the path exists and is executable.

func IsFile

func IsFile(path string) bool

IsFile is a function that returns true if the path exists and is a regular file, i.e. not a directory, symlink, block device, etc.

func IsOwner

func IsOwner(path string) bool

IsOwner is a function that returns true if the path exists and is owned by the current user.

func IsReadable

func IsReadable(path string) bool

IsReadable is a function that returns true if the path exists and is readable.

func IsSymlink(path string) bool

IsSymlink is a function that returns true if the path exists and is a symlink.

func IsWritable

func IsWritable(path string) bool

IsWritable is a function that returns true if the path exists and is writable.

func Map

func Map[T, U any](s []T, f func(T) U) []U

func Max

func Max[T Number](s []T) T

Max returns the maximum value in a slice of numbers.

func Min

func Min[T Number](s []T) T

Min returns the smallest element in a slice of numbers.

func Normalise

func Normalise(s string) string

Normalise is a function that returns a lowercase version of a string with leading and trailing whitespace removed.

func PathExists

func PathExists(path string) bool

PathExists is a function that returns true if the path exists, whether it is a file, directory, symlink, or anything else.

func PrintBlue

func PrintBlue(s string)

PrintBlue is a function that prints a string in blue.

func PrintBold

func PrintBold(s string)

PrintBold is a function that prints a string in bold.

func PrintClear

func PrintClear()

PrintClear is a function that clears the terminal screen.

func PrintClearLine

func PrintClearLine()

PrintClearLine is a function that clears the current line.

func PrintCyan

func PrintCyan(s string)

PrintCyan is a function that prints a string in cyan.

func PrintGreen

func PrintGreen(s string)

PrintGreen is a function that prints a string in green.

func PrintMagenta

func PrintMagenta(s string)

PrintMagenta is a function that prints a string in magenta.

func PrintRed

func PrintRed(s string)

PrintRed is a function that prints a string in red.

func PrintReset

func PrintReset()

PrintReset is a function that resets the terminal to its default state.

func PrintUnderline

func PrintUnderline(s string)

PrintUnderline is a function that prints a string in underline.

func PrintWhite

func PrintWhite(s string)

PrintWhite is a function that prints a string in white.

func PrintYellow

func PrintYellow(s string)

PrintYellow is a function that prints a string in yellow.

func RandomChoice

func RandomChoice[T any](s []T) T

RandomChoice is a function that returns a random element from a slice.

func RandomInt

func RandomInt(min, max int) int

RandomInt is a function that returns a random integer between min and max. To generate a large number of random integers, use RandomSequence instead.

func RandomRange

func RandomRange(min, max, length int) []int

RandomRange is a function that returns a slice of random integers between min and max.

func RandomSequence

func RandomSequence(min, max, length int) chan int

RandomSequence is a function that returns a channel of random integers between min and max. This method is more efficient than RandomRange, and can be used to generate an arbitrarily large number of random integers.

func RemoveIndex

func RemoveIndex[T any](s []T, i int) []T

RemoveIndex is a function that removes an item by index from a slice and returns the resulting slice.

func RemoveItems

func RemoveItems[T comparable](s []T, item T, max int) []T

RemoveItems is a function that removes items by value from a slice, up to a "max" times, and returns the resulting slice. If max is 0, all items are removed.

func ReverseSlice

func ReverseSlice[T any](s []T) []T

ReverseSlice reverses a slice of any type.

func ReverseString

func ReverseString(s string) string

ReverseString is a function that reverses a string and returns the result.

func Shuffle

func Shuffle[T any](slice []T)

Shuffle is a function that shuffles a slice in-place using the Fisher-Yates algorithm.

func SumSlice

func SumSlice[T Number](s []T) T

SumSlice is a function that sums the elements of a slice and returns the result.

Types

type Number

Number is an interface that represents any number type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL