GithubHelp home page GithubHelp logo

minhphu0304 / gofunc Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 1.96 MB

Utility library for Golang programmers. Inspired by Ramdajs

License: MIT License

Go 100.00%
go golang functional-programming golang-programmers utility utility-function

gofunc's Introduction

go functional

Go-Functional

Build Status GitHub GitHub top language

Functional library for Golang programmers. Inspired by Ramda JS and Lodash

Available functions

  • AddInt: Add all integer in parameters together

Example:

  import (
    gofunc "https://github.com/MinhPhu0304/gofunc"
  )
  func main() {
    input := 1
    gofunc.AddInt(input) // Expected: 1
    gofunc.AddInt(1,2,3) // Expected: 6
  }
  • AddString: Add all integer in parameters together with a space between each parameters

Example:

    import (
      gofunc "https://github.com/MinhPhu0304/gofunc"
    )
    func main() {
      input := "Hello"
      gofunc.AddString(input) // Expected: Hello
      gofunc.AddString(input, "world") // Expected: Hello world
    }
  • All: Return true if all elements of the list match the predicate

Example:

    import (
      gofunc "https://github.com/MinhPhu0304/gofunc"
    )

    func main () {
      input := []int{3,3,3}
      input2 := []string{"hey","hey"}
      checkAllElementIs3 := gofunc.All(3)
      checkAllElementIs3(input) // Return true
      checkAllElementIs3(input2) // Return false
    }
  • First: Get the first element of any array type

Example:

    import (
      gofunc "https://github.com/MinhPhu0304/gofunc"
    )
    func main() {
      input := [3]int {1,2,3}
      gofunc.First(input) // Expected: 1
      stringInput := [3]string {"Hello", "Go", "developers"}
      gofunc.First(stringInput) // Expected: Hello
    }
  • Last: Get the last element of any array type

Example:

    import (
      gofunc "https://github.com/MinhPhu0304/gofunc"
    )
    func main() {
      input := [3]int {1,2,3}
      gofunc.Last(input) // Expected: 3
      stringInput := [3]string {"Hello", "Go", "developers"}
      gofunc.Last(stringInput) // Expected: developers
    }
  • Sum: Add all value in an integer list

Example:

    import (
      gofunc "https://github.com/MinhPhu0304/gofunc"
    )
    func main () {
      array := []int{1, 2, 3}
      gofunc.Sum(array) // Expected: 6
    }
  • Always: Return curried function which always return value passed in

Example:

    import (
      gofunc "https://github.com/MinhPhu0304/gofunc"
    )
    func main () {
      alwaysTrue := gofunc.Always(true)
      alwaysTrue() // return true      
    }
  • Prop: Return field value of a struct if present. Note: all field should be export from the struct

Example:

    import (
      gofunc "https://github.com/MinhPhu0304/gofunc"
    )

    type Person struct {
	    Name string
    }

    func main () {
      test := Person{Name: "test"}
      name := gofunc.Prop("Name", test) // Return "test"
    }

gofunc's People

Contributors

minhphu0304 avatar waltzaround avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.