Giter Site home page Giter Site logo

sonlamho / gopy Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 38 KB

makes Go (>=1.18) feels more like Python with generic functions

License: MIT License

Go 100.00%
python golang functional-programming map reduce generic-functions generic-programming go

gopy's Introduction

gopy

Github Actions Go Reference

Features

  • Minimal, no bloat, pure functions (no side-effects), sensible function signatures (following Python mostly), no dependencies, pure Go!
  • Basic functional tools: Map, Filter, Reduce, Reversed
  • Reducing functions: Sum, Min, Max, All, Any
  • Variadic version of some functions: VarSum, VarMin, VarMax, VarAll, VarAny

Example Usage

Before using gopy in your project, get the package: go get github.com/sonlamho/gopy@latest

Sample code below:

package main

import (
	"fmt"
	"github.com/sonlamho/gopy"
)

var Print = fmt.Println

func main() {
	seq := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
	add_1half := func(x int) float64 { return float64(x) + 0.5 }
	is_even := func(x int) bool { return x%2 == 0 }

	Print(seq)
	Print(gopy.Map(add_1half, seq))
	Print(gopy.Filter(is_even, seq))
	Print(gopy.Sum(seq))
	Print("---")
	Print(gopy.Min(seq))  // -> 1
	Print(gopy.VarMin(100, 50, 9, 42))  // -> 9
	Print(gopy.VarMin(0.5, 0.7))  // -> 0.5
}

Output:

[1 2 3 4 5 6 7 8 9 10]
[1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5]
[2 4 6 8 10]
55
---
1
9
0.5

Future Plan:

  • Same operations Map, Filter, etc. but on iterables instead of slices.

gopy's People

Contributors

sonlamho avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.