Skip to content
orashusPublic

About

A light weight collection of generic Go utility functions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

go-utils

A small collection of generic Go utility functions.

Requirements

  • Go 1.26.3 or later

Installation

go get github.com/orashus/go-utils

Usage

Import the package in your Go module:

import gu "github.com/orashus/go-utils"

Map

Map transforms each element of a slice using a callback and returns a new slice with the results. The callback receives the element value and its index.

package main

import (
 "fmt"
 "strconv"

 gu "github.com/orashus/go-utils"
)

func main() {
 nums := []int{1, 2, 3, 4}

 strs := gu.Map(nums, func(n int, i int) string {
  return strconv.Itoa(n * i)
 })

 fmt.Println(strs) // [0 2 6 12]
}

API

Function Description
Map[T, V](arr []T, fn func(T, int) V) []V Applies fn to each element of arr and returns a new slice of transformed values.

About

A light weight collection of generic Go utility functions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages