All Projects → shrugs → Fauxgaux

shrugs / Fauxgaux

⛳️ Functional Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Fauxgaux

Funktionale
Functional constructs for Kotlin
Stars: ✭ 879 (+2341.67%)
Mutual labels:  functional-programming
Docker Iocaml Datascience
Dockerfile of Jupyter (IPython notebook) and IOCaml (OCaml kernel) with libraries for data science and machine learning
Stars: ✭ 30 (-16.67%)
Mutual labels:  functional-programming
Shell Functools
Functional programming tools for the shell
Stars: ✭ 971 (+2597.22%)
Mutual labels:  functional-programming
Mori Ext
Function bind syntax wrappers for mori
Stars: ✭ 15 (-58.33%)
Mutual labels:  functional-programming
Immutable Tuple
Immutable finite list objects with constant-time equality testing (===) and no memory leaks.
Stars: ✭ 29 (-19.44%)
Mutual labels:  functional-programming
Swiftlyext
SwiftlyExt is a collection of useful extensions for Swift 3 standard classes and types 🚀
Stars: ✭ 31 (-13.89%)
Mutual labels:  functional-programming
Mappy
A functional programming language. Like LISP but focused around maps rather than lists.
Stars: ✭ 10 (-72.22%)
Mutual labels:  functional-programming
Imagene
A General Purpose Image Manipulation Tool
Stars: ✭ 36 (+0%)
Mutual labels:  functional-programming
Purrr
A functional programming toolkit for R
Stars: ✭ 953 (+2547.22%)
Mutual labels:  functional-programming
Swift Overture
🎼 A library for function composition.
Stars: ✭ 968 (+2588.89%)
Mutual labels:  functional-programming
Opal
Simple and powerful programming language with type inference
Stars: ✭ 20 (-44.44%)
Mutual labels:  functional-programming
Enum Fp
Functional Enum type / Sum type for javascript with simple pattern matching
Stars: ✭ 27 (-25%)
Mutual labels:  functional-programming
Flawless
WIP Delightful, purely functional testing no-framework. Don't even try to use it at work!
Stars: ✭ 33 (-8.33%)
Mutual labels:  functional-programming
Bugz
🐛 Composable User Agent Detection using Ramda
Stars: ✭ 15 (-58.33%)
Mutual labels:  functional-programming
Rexrex
🦖 Composable JavaScript regular expressions
Stars: ✭ 34 (-5.56%)
Mutual labels:  functional-programming
Revery Playground
Live, interactive playground for Revery examples
Stars: ✭ 14 (-61.11%)
Mutual labels:  functional-programming
Oqaml
An OCaml based implementation of a Quil QVM
Stars: ✭ 31 (-13.89%)
Mutual labels:  functional-programming
Corsair
Corsair using RxJS, Immutable.js and WebGL/three.js
Stars: ✭ 36 (+0%)
Mutual labels:  functional-programming
Stm4cats
STM monad for cats-effect
Stars: ✭ 35 (-2.78%)
Mutual labels:  functional-programming
Ulmus
A functional-reactive style programming library for Clojure(script)
Stars: ✭ 33 (-8.33%)
Mutual labels:  functional-programming

FauxGaux - Functional Go

Named FauxGaux because this isn't very idiomatic.

Disclaimer

This is for learning purposes and the hell of it. Please do not actually use in a project.

This probably has an awful memory profile; don't look at it.

I have given minimal thought to error handling. As such, there is none.

Installation

go get github.com/Shrugs/fauxgaux

Usage

Map

Takes a function. This function must accept one argument of arbitrary type and return one argument of arbitrary type.

nums := &[]int{1, 2, 3, 4}
nums = Chain(nums).Map(func(i int) int {
    return i + 1
}).ConvertInt()
fmt.Println(nums)
// [2 3 4 5]
words := &[]string{"Hello", "What's up", "Howdy"}
words = Chain(words).Map(func(s string) string {
    return strings.Join([]string{s, "World!"}, " ")
}).ConvertString()
fmt.Println(words)
// [Hello World! What's up World! Howdy World!]

ParallelMap

Same as map, but creates a worker goroutine for each element in the slice. Uses sync.WaitGroup to wait for all elements before continuing the chain.

// in series, function would sleep for 5 seconds
// with ParallelMap, only sleeps for 1
nums := &[]int{0, 1, 2, 3, 4}
newNums := Chain(nums).ParallelMap(func(i int) int {
    time.Sleep(time.Second)
    return i
}).ConvertInt()

// ok   github.com/Shrugs/fauxgaux  1.007s

Reduce

Takes a function and an accumulator. Function must accept the accumulator and the current object (using the correct types, naturally) and return the accumulator (with type unchanged).

User must instantiate accumulator to some value.

people := &[]*Person{
    &Person{"Matt", 20},
    &Person{"Ben", 19},
}

totalAge := fauxgaux.Chain(people).Map(func(p *Person) int {
    return p.Age
}).Reduce(func(i int, num int) int {
    i += num
    return i
}, 0).(int)

fmt.Println(totalAge)
// 39
nums := &[]int{1, 2, 3, 4, 5}
sum := Chain(nums).Reduce(func(i int, num int) int {
    i += num
    return i
}, 0).(int)
fmt.Println(sum)

// 15

Each

Same as Map, but does not replace the values of the chained slice; it only modifies them in memory. As such, the function passed must only accept one argument of the correct type.

type Person struct {
    Name string
    Age  int
}

people := &[]*Person{
    &Person{"Matt", 20},
    &Person{"Ben", 19},
    &Person{"Sam", 21},
}

fauxgaux.Chain(people).Each(func(p *Person) {
    p.Name = "test"
})

for _, p := range *people {
    fmt.Println(p.Name)
}

// test test test

Filter

Filters the slice based on a conditional function. Function should accept one argument of the correct type and return a bool indicating whether or not to keep the element in the slice.

nums := &[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
evenSum := fauxgaux.Chain(nums).Filter(func(i int) bool {
    return math.Mod(float64(i), 2) == 0
}).Reduce(func(sum, num int) int {
    sum += num
    return sum
}, 0).(int)

fmt.Println(evenSum)
// 30
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].