Functional programming library for Go including a lazy list implementation and some of the most usual functions.

functional

A functional programming library including a lazy list implementation and some of the most usual functions.

import FP "github.com/tcard/functional"

Installing

go get github.com/tcard/functional

Tested on Go 1.

Build Status

Examples

The Fibonacci sequence, infinite stream:

var fibo *FP.Thunk
fibo = FP.Link(1, FP.DelayedLink(1, func() *FP.Thunk {
	return FP.MapN(func(xs ...FP.I) FP.I {
		ret := 0
		for _, v := range xs {
			ret += v.(int)
		}
		return ret
	}, fibo, fibo.Tail())
}))

Which is an uglier, slower version of the famous Lisp-like:

(define fibo
	(cons 1
		(cons 1
			(map + fibo (cdr fibo)))))		

For showing some "real" utility, this would retrieve the third page of a blog:

var posts *FP.Thunk	= ...
page := 3
postsPerPage := 10
_ = posts.Drop((page - 1) * postsPerPage).Take(postsPerPage).Map(func (post FP.I) FP.I {
	blog.showPost(post.(Post))
	return post
})

See documentation and tests for detailed usage.

To Do

  • Better memoization.
  • Ability to skip lists and work directly with slices, although lack of generics would make it clumsy anyway.
  • Some optimizations.
Similar Resources

skiptable is a jump table that mimics redis' zset using go, and implements most of the features of redis zset

skiptable is a jump table that mimics redis' zset using go, and implements most of the features of redis zset

Oct 25, 2021

A simple Cron library for go that can execute closures or functions at varying intervals, from once a second to once a year on a specific date and time. Primarily for web applications and long running daemons.

Cron.go This is a simple library to handle scheduled tasks. Tasks can be run in a minimum delay of once a second--for which Cron isn't actually design

Dec 17, 2022

Geth client which picks the most profitable blocks to mine using a greedy algorithm

Greeden-Geth Greeden-Geth is a protocol-agnostic client which uses a greedy algorithm to pick the most profitable blocks to submit to the network out

Nov 16, 2022

Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Oct 1, 2021

An application dedicated to the trivial and boring task of meal planning 📅 and generating shoppings list 🛒.

An application dedicated to the trivial and boring task of meal planning 📅 and generating shoppings list 🛒.

An application dedicated to the trivial and boring task of meal planning 📅 and generating shoppings list 🛒.

Mar 1, 2022

Some examples of testing techniques and commonly used frameworks

golang-test-examples Some examples of testing techniques and commonly used frameworks Test frameworks Testify Ginkgo Convey godog (cucumber) Test exam

Oct 29, 2021

Flow-based and dataflow programming library for Go (golang)

Flow-based and dataflow programming library for Go (golang)

GoFlow - Dataflow and Flow-based programming library for Go (golang) Status of this branch (WIP) Warning: you are currently on v1 branch of GoFlow. v1

Dec 30, 2022

Onboarding exercise to create todo list using golang and postgres

Todo List API Description A RESTful API that allows a user to create, update, view, filter, and delete todos API Documentation Copy the contents of th

Dec 1, 2021

Listmonk - a standalone, self-hosted, newsletter and mailing list manager

Listmonk - a standalone, self-hosted, newsletter and mailing list manager

listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a Postg

Jan 13, 2022
Functional Programming support for golang.(Streaming API)

Funtional Api for Golang Functional Programming support for golang.(Streaming API) The package can only be used with go 1.18. Do not try in lower vers

Dec 8, 2021
Go module that provides primitive functional programming utilities.

Functional Functional provides a small set of pure functions that are common in functional programming languages, such as Reduce, Map, Filter, etc. Wi

Jun 12, 2022
Typesafe lazy instantiation to improve service start time

Package lazy is a light wrapper around sync.Once providing support for return values. It removes the burden of capturing return values via closures from the caller.

May 30, 2022
Some convenient string functions.

str Some convenient string functions. What This package containsa couple of functions to remove duplicates from string slices and optionally sort them

Dec 27, 2021
Generic-list-go - Go container/list but with generics

generic-list-go Go container/list but with generics. The code is based on contai

Dec 7, 2022
The package manager for macOS you didn’t know you missed. Simple, functional, and fast.
The package manager for macOS you didn’t know you missed. Simple, functional, and fast.

Stew The package manager for macOS you didn’t know you missed. Built with simplicity, functionality, and most importantly, speed in mind. Installation

Mar 30, 2022
Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Advent of Code 2021 Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved

Dec 2, 2021
Jan 4, 2022
Radiant is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services.

Radiant is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services.

Mar 22, 2022
A patcher for the MS-DOS version of Fallout 1 including Crafty's sFall1 patches and maybe more

A patcher for the MS-DOS version of Fallout 1 including Crafty's sFall1 patches and maybe more

Oct 13, 2022