Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/anaseto/grid

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/anaseto/grid

  • v0.2.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Grid

pkg.go.dev godocs.io

The grid module and package provide a generic implementation of a two-dimensional matrix slice type. The API is inspired both by the standard Go slice builtin functions and the image standard package.

It makes no assumptions on the type of the cells, and provides optimized generic methods for grid iteration and manipulation.

Here's a simple example of usage:

// Create a new 10x10 grid of runes.
gd := grid.NewGrid[rune](10, 10)
// Fill the whole grid with dots.
gd.Fill('.')
// Define a range (3,3)-(7,7).
rg := grid.NewRange(3, 3, 7, 7)
// Define a slice of the grid using the range.
rectangle := gd.Slice(rg)
// Fill the rectangle with #.
rectangle.Fill('#')
// Print the grid.
it := gd.Iterator()
max := gd.Size()
for it.Next() {
	fmt.Printf("%c", it.V())
	if it.P().X == max.X-1 {
		fmt.Print("\n")
	}
}
// Output:
// ..........
// ..........
// ..........
// ...####...
// ...####...
// ...####...
// ...####...
// ..........
// ..........
// ..........

See the documentation for more examples.

FAQs

Package last updated on 22 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc