Skip to content

Latest commit

 

History

History
199 lines (157 loc) · 9.92 KB

README.md

File metadata and controls

199 lines (157 loc) · 9.92 KB

Golem

"Scrap Your Boilerplate" for Go

sub-moduledocabout
Heterogenous sequence of types
Composable getters and setters (lenses) for manipulating data structures
Type safe channels and data pipeline combinator.
Generic purely functional abstractions (e.g. HKT, Monoid, etc).
Generic behavior traits.


His dust was "kneaded into a shapeless husk."

You could do this with a macro, but... the best macro is a macro you don't maintain

Golem is a purely functional and generic programming library for Go. It has its origins in Purely Functional Data Structures by Chris Okasaki, and implements various functional abstractions and patterns, deals with scrap your boilerplate and benefits from the experience of other functional languages, primary Scala, Haskell and also heavily inspired by the Erlang library datum. Golem is testing the limits of functional abstractions in Go.

Inspiration

Functional Programming is a declarative style of development that uses side effect free functions to express the solution of the problem domain. The core concepts of functional programming are elaborated by Martin Odersky - First class and high-order functions and immutability. Another key feature in functional programming is the composition - a style of development to build new things from small reusable elements. Functional code looks great only if functions clearly describe your problem. Usually, lines of code per function is only a single metric that reflects the quality of the code

If your functions have more than a few lines of code (a maximum of four to five lines per function is a good benchmark), you need to look more closely — chances are you have an opportunity to factor them into smaller, more tightly focused functions

This is because functions describe the solution to your problem. If your code contains many lines, then it is highly likely, that you are solving few problems without explicitly articulating them. And critical thinking is the process of software development - Write small blocks of code.

Functional style programming can be achieved in any language, including Go. Golang's structural type system helps to reject invalid programs at compilation time. One of the challenge here is, that Go's structures, arrays, slices and maps embrace mutability rather than restricting it. Scala is a good example of the language that uses an imperative runtime but provides data structure implementations that inherently avoid mutation. This is a perfect approach to achieve immutability and performance through well-defined scopes. All-in-all, Go is a general purpose language with simple building blocks. This library uses these blocks to implement a functional style of development with the goal of simplicity in mind.

Getting started

The library requires Go 1.18 or later due to usage of generics.

The latest version of the library is available at main branch. All development, including new features and bug fixes, take place on the main branch using forking and pull requests as described in contribution guidelines. The stable version is available via Golang modules.

  1. Use go get to retrieve the library and add it as a dependency to your application.
go get -u github.com/fogfish/golem/{submodule}
  1. Import required package in your code
import (
  "github.com/fogfish/golem/{submodule}"
)

Examples and show cases

How To Contribute

The library is MIT licensed and accepts contributions via GitHub pull requests:

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

The build and testing process requires Go version 1.18 or later.

Build and run in your development console.

git clone https://github.com/fogfish/golem
cd golem/{submodule}
go test ./...

License

See LICENSE