godash

package module
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 1 Imported by: 0

README

godash

Modeled after the lodash library Javascript/Typescript, godash is a collection of useful functions for working with slices/arrays, maps, sets, hashable sets, optionals and more. It is meant to help you write more concise and readable code in a functional way.

Work in progress, I will be adding more functions as I need them/as I have time. Feel free to contribute. You can either contribute by adding functions, by adding tests or by adding documentation.

Only functions that are themselves written and are unit tested are marked as done unless they are one-liners. Function that do not have tests are marked with a - instead of a x. Use of functions marked with - is highly discouraged.

Install

go get github.com/GrewalAS/godash

Planned/In Progress:

  • Functions

    • [-] Memoize
    • [-] Negate
    • Throttle
  • Priority Queue

    • Insert (inserts an element with priority)
    • Peek (returns the highest priority element)
    • Pop (removes and returns the highest priority element)
    • IsEmpty
    • Size
  • Graphs

    • Directed
    • Undirected
    • Weighted
    • Unweighted
    • Trees
      • Binary Search Trees
      • Binary Trees
      • AVL Trees
      • Red-Black Trees
  • Trie

    • Insert
    • Search
    • StartsWith
    • Remove

Completed:

  • Conditions

    • ComparableEquality
    • NumberEquality
    • NumberLessThan
    • NumberLessThanOrEqual
    • NumberGreaterThan
    • NumberGreaterThanOrEqual
    • HashableEquality
    • AnyEquality
  • Types

    • Number
    • Pair
    • Hashable
    • Iterable
  • Utils

    • Option
    • Panics
    • Result
    • Testing
  • Maps

    • Add - Modifies original DS, does not return a new one
    • AddAll - Modifies original DS, does not return a new one
    • Contains
    • FromMap
    • Keys
    • Remove - Modifies original DS, does not return a new one
    • RemoveAll - Modifies original DS, does not return a new one
    • ToMap
    • Values
  • HashableMap

    • Add - Modifies original DS, does not return a new one
    • AddAll - Modifies original DS, does not return a new one
    • Contains
    • FromHashableMap
    • Keys
    • Remove - Modifies original DS, does not return a new one
    • RemoveAll - Modifies original DS, does not return a new one
    • ToHashableMap
    • Values
  • Set

    • Add - Modifies original DS, does not return a new one
    • AddAll - Modifies original DS, does not return a new one
    • Contains
    • Difference
    • FromSet
    • Intersection
    • IsSubsetOf
    • IsSupersetOf
    • Remove - Modifies original DS, does not return a new one
    • RemoveAll - Modifies original DS, does not return a new one
    • ToSet
    • Union
  • HashableSet

    • Add - Modifies original DS, does not return a new one
    • AddAll - Modifies original DS, does not return a new one
    • Contains
    • Difference
    • FromHashableSet
    • Intersection
    • IsSubsetOf
    • IsSupersetOf
    • Remove - Modifies original DS, does not return a new one
    • RemoveAll - Modifies original DS, does not return a new one
    • Size
    • ToHashableSet
    • Union
  • Slices/Arrays

    • Chunk
    • Compact
    • Contains
    • ContainsHashable
    • ContainsWith
    • Difference
    • DifferenceHashable
    • DifferenceWith
    • Filter
    • Flatten
    • ForEach
    • Head // One liner, no tests
    • Intersection
    • IntersectionHashable
    • IntersectionWith
    • Map
    • Tail // One liner, no tests
    • Union
    • UnionHashable
    • UnionWith
    • Unzip
    • Zip
    • ZipWithIndex
    • Sample
    • SampleWithSeed
    • SampleN
    • SampleNWithSeed
    • Shuffle
    • ShuffleWithSeed
  • Linked List

    • AddFirst
    • AddLast
    • Clear
    • Contains
    • FromSlice
    • Get
    • Insert
    • Remove
    • ToSlice
  • Search

    • LinearSearch
    • BinarySearch
    • Bisect
      • BisectLeftWith
      • BisectWith
      • BisectRightWith
  • Queue // Incredibly simple, no tests

    • Enqueue
    • Dequeue
    • Peek
    • Size
  • Stack // Incredibly simple, no tests

    • Push
    • Pop
    • Peek
    • Size
  • Strings/strutil

    • CamelCase
    • SnakeCase
    • KebabCase
    • PadLeft
    • PadRight
    • Pad
    • Truncate

Documentation

Overview

Package godash provides a collection of utility functions for Go, inspired by JavaScript's lodash library.

Package godash is a collection of various utilities for Go.

Package godash provides a collection of utility functions for Go, inspired by JavaScript's lodash library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyEquality

func AnyEquality[A any](a, b A) bool

AnyEquality Compares two values of any type and returns true if they are equal using reflect.DeepEqual.

func ComparableEquality

func ComparableEquality[A comparable](a, b A) bool

ComparableEquality Compares two values of type comparable and returns true if they are equal.

func HashableEquality

func HashableEquality[A Hashable, B Hashable](a A, b B) bool

HashableEquality compares two values of any type that implement the Hashable interface and returns true if they are equal.

func NumberEquality added in v0.6.8

func NumberEquality[N Number](a, b N) bool

NumberEquality compares two numbers and returns true if they are equal.

func NumberGreaterThan added in v0.6.8

func NumberGreaterThan[N Number](a, b N) bool

NumberGreaterThan compares two numbers and returns true if a is greater than b.

func NumberGreaterThanOrEqual added in v0.6.8

func NumberGreaterThanOrEqual[N Number](a, b N) bool

NumberGreaterThanOrEqual compares two numbers and returns true if a is greater than or equal to b.

func NumberLessThan

func NumberLessThan[N Number](a, b N) bool

NumberLessThan compares two numbers and returns true if a is less than b.

func NumberLessThanOrEqual added in v0.6.8

func NumberLessThanOrEqual[N Number](a, b N) bool

NumberLessThanOrEqual compares two numbers and returns true if a is less than or equal to b.

Types

type Hashable

type Hashable interface {
	// Hash returns a string representation of the value.
	Hash() string
}

Hashable is an interface that represents any type that can be converted to a string using a hash function.

type Iterable

type Iterable[T any] interface {
	[]T | string
}

Iterable is an interface that represents any type that can be iterated over.

type Number

type Number interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64
}

Number is an interface that represents any numeric type.

type Pair

type Pair[T, U any] struct {
	First  T
	Second U
}

Pair is a pair of two values.

Directories

Path Synopsis
Package functions contains higher-order functions that are useful for various purposes.
Package functions contains higher-order functions that are useful for various purposes.
Package hashablemaps offers tools for handling and manipulating map data structures with hashable keys.
Package hashablemaps offers tools for handling and manipulating map data structures with hashable keys.
Package hashablesets provides functionality for creating and manipulating set data structures with hashable elements.
Package hashablesets provides functionality for creating and manipulating set data structures with hashable elements.
Package linkedlist provides functionality for creating and manipulating doubly linked lists.
Package linkedlist provides functionality for creating and manipulating doubly linked lists.
Package maps provides functions for manipulating maps.
Package maps provides functions for manipulating maps.
Package queues offers various utilities for handling and manipulating queues data structures.
Package queues offers various utilities for handling and manipulating queues data structures.
Package search provides various linear search, bisect search, and bisect insertion functions.
Package search provides various linear search, bisect search, and bisect insertion functions.
Package sets provides functionality for creating and manipulating set data structures.
Package sets provides functionality for creating and manipulating set data structures.
Package slices offers various utilities for handling and manipulating slice data structures.
Package slices offers various utilities for handling and manipulating slice data structures.
Package stacks offers various utilities for handling and manipulating stack data structures.
Package stacks offers various utilities for handling and manipulating stack data structures.
Package strutil contains various string manipulation utilities.
Package strutil contains various string manipulation utilities.
Package utils contains a collection of utility functions that can be used throughout the Go application.
Package utils contains a collection of utility functions that can be used throughout the Go application.

Jump to

Keyboard shortcuts

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