Simple and expressive toolbox written in Go

GoDoc Go Report Card Travis CI

ugo

Simple and expressive toolbox written with love and care in Go.

Deeply inspired by underscore.js and has the same syntax and behaviour

Fully covered with tests, no surprises

Quick start

Installation

go get -u  github.com/alxrm/ugo

Import

import (
	u "github.com/alxrm/ugo"
)

Usage

It works with some special type, named Seq, which is an alias for []interface{}

So let's make some

	
// creates the new string Seq
strSeq := u.Seq{ "nineteen", "eigth", "four" } // ["nineteen" "eigth" "four"]
	
// creates the new Seq with given length
emptySeq := u.NewSeq(0); // []
	
// copies reflectively all of the values from int slice to Seq
intSlc := []int{ 4, 6, 2, 7, 8, 10, 9, 9, 120, 10, 2, 17 }
intSeq := u.From(intSlc, len(intSlc)) // [4 6 2 7 8 10 9 9 120 10 2 17]

Actually reflection approach in u.From can have an impact on performance 🐌 so use it with care.

Okay, now we have some Seq's,

What if I want to leave only unique elements in my int slice?

Go and get it ⚑

initialSeq := u.Seq{ 4, 6, 2, 7, 8, 10, 9, 9, 120, 10, 2, 17 }
uniquedSeq := u.Uniq(initial, func(l, r u.Object) int { return l.(int) - r.(int) })

fmt.Println(uniquedSeq) // [4 6 2 7 8 10 9 120 17]

And I want to leave only odd ones

Nice choice! πŸ”₯

oddsSeq := u.Filter(uniquedSeq, func(cur, _, _ u.Object) bool { return cur.(int) % 2 != 0 })

fmt.Println(oddsSeq) // [7 9 17]

Well, sometimes you may want to use many method one by one, and it can be a bit ugly

Here we are, fluent syntax, just like in underscore.js πŸš€

initialSeq := u.Seq{ 4, 6, 2, 7, 8, 10, 9, 9, 120, 10, 2, 17 }

res := u.Chain(initialSeq).Uniq(func(l, r u.Object) int {
	return l.(int) - r.(int)
}).Filter(func(cur, _, _ u.Object) bool {
	return cur.(int) % 2 != 0
}).Value()

fmt.Println(res) // [7 9 17]

Try it by yourself!

Explore all of the features and get your slice routine done faster

Contribute

We highly appreciate any of your pull requests and issues!

Be welcome β˜•

Some of the TODOs:

  • Aliases from underscore
  • Chaining like map(...).uniq(...).result()
  • Better documentation

License

The MIT License (MIT)

Copyright (c) 2016 Alexey Derbyshev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Owner
Alexey Derbyshev
Alexey Derbyshev
Similar Resources

go-simple-geo is a library for simple geo calculations.

go-simple-geo is a library for simple geo calculations. Installation go get github.com/EpicStep/go-simple-geo Example package main import ( "github.

Dec 4, 2022

jacobin - A more than minimal JVM written in Go and capable of running Java 11 bytecode.

This overview gives the background on this project, including its aspirations and the features that it supports. The remaining pages discuss the basics of JVM operation and, where applicable, how Jacobin implements the various steps, noting any items that would be of particular interest to JVM cognoscenti.

Dec 29, 2022

An atomic counter that also tracks and calculates a rate written in Go.

An atomic counter that also tracks and calculates a rate written in Go.

Oct 27, 2021

A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

Dec 31, 2021

A toy language parser, lexer and interpreter written in Golang

Monkey - A toy programming language Monkey is a toy programming language used to learn how to write a lexer, parser and interpreter. The language is i

Nov 16, 2021

Catfetch is a small and cute fetch program written in Go

 Catfetch is a small and cute fetch program written in Go

🐱Catfetch is a small and cute fetch program written in Go

Oct 30, 2022

gopbin is a minimalist and opinionated pastebin implementation written in Go.

gopbin gopbin is a minimalist and opinionated pastebin implementation written in

Dec 28, 2021

Various Dungeons and Dragons Tools. Written in go as an aid to learning the language.

dnd_tools Various Dungeons and Dragons Tools. Written in go as an aid to learning the language. Some tools are generic, while others will target eithe

Jan 28, 2022

GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself.

GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way  to say thanks to the maintainers of the modules you use and the contributors of Go itself.

Give thanks (in the form of a GitHub β˜…) to your fellow Go modules maintainers. About GoThanks performs the following operations Sends a star to Go's r

Dec 24, 2022
Simple 'UserKit' for Malware written in Go. Startup, Hidden Files, Critical Process and Registry Watcher

GoUserKit Simple UserKit for Malware written in Go Features Makes Process Critical (NtSetInformationProcess) Hides Files Simple Add to Startup (HKCU R

Jan 3, 2023
A simple and sussy project is an implementation of SOMMIP Lab 1 written in Golang
A simple and sussy project is an implementation of SOMMIP Lab 1 written in Golang

SOMMIP Lab 1 Isac Arthur Table of Contents About The Project Getting Started Prerequisites Installation Supported commands About The Project This very

Nov 10, 2021
πŸ§€ Formaggo is a simple model checker inspired by TLA+, The checker and the models are written in Go

?? Formaggo. A cheesy exhaustive state checker in Go. Formaggo is a simple model checker inspired by TLA+. The checker and the models are written in G

Jan 23, 2022
A simple typewriter written in go for KOBO e-readers
A simple typewriter written in go for KOBO e-readers

Kobowriter This small project aims to let you use your old KOBO e-reader (mine is a GLO HD) as a simple, distraction free typewriter. For years I thou

Dec 25, 2022
Person is a simple CRUD application written in go which exposes API endpoint to create the person.

Person Person is a simple CRUD application written in go which exposes API endpoint to create the person. Installation Install docker in your local sy

Oct 18, 2021
A simple project/module generated tool written in go

A module generator written in go This is a project/module generator written in go. It is intended to generate standard project/module layouts in the t

Oct 17, 2022
Simple cross platform fetch program, written in Go
Simple cross platform fetch program, written in Go

nextfetch Simple cross platform fetch program, written in Go Prerequisites True color (24-bit) or 256-color (8-bit) compatible terminals go >= 17 (bui

Oct 31, 2022
bf.go - A dead simple brainfuck interpreter Slow and simple

bf.go - A dead simple brainfuck interpreter Slow and simple. Can execute pretty much all tested Brainfuck scripts. Installation If you have Go install

Oct 15, 2021
Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and traditional RESTful API.

Phalanx Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and tr

Dec 25, 2022
Highly extensible, customizable application launcher and window switcher written in less than 300 lines of Golang and fyne
Highly extensible, customizable application launcher and window switcher written in less than 300 lines of Golang and fyne

golauncher A go application launcher A simple, highly extensible, customizable application launcher and window switcher written in less than 300 lines

Aug 21, 2022