Skip to content

RPG-18/concurrent

Repository files navigation

Simple MapReduce on Go

Test GoDoc

Package concurrent provides high-level APIs for concurrent programming. Package implemented Qt Concurrent API

Examples

Map

package main

import (
	"fmt"
	concurrent "github.com/RPG-18/concurrent"
)

func main() {
	numbers := []int{1, 2, 3, 4, 5, 6}
	_ = concurrent.Map(4, numbers, func(value *int) {
		*value *= 2
	})

	fmt.Println(numbers) // [2 4 6 8 10 12]
}

Mapped

package main

import (
	"fmt"
	"strconv"

	concurrent "github.com/RPG-18/concurrent"
)

func main() {
	numbers := []int{1, 2, 3, 4, 5, 6}
	strings, _ := concurrent.Mapped(4, numbers, func(value int) string {
		return strconv.Itoa(value)
	})

	fmt.Println(strings) // [1 2 3 4 5 6]
}

MappedReduced

package main

import (
	"fmt"
	"strconv"

	concurrent "github.com/RPG-18/concurrent"
)

func main() {
	numbers := []int{1, 2, 3, 4, 5, 6}
	ordered, _ := concurrent.MappedReduced(3, numbers, func(value int) string {
		return strconv.Itoa(value)
	}, func(sum *string, value string) {
		*sum = *sum + value
	}, concurrent.OrderedReduce)
	unordered, _ := concurrent.MappedReduced(3, numbers, func(value int) string {
		return strconv.Itoa(value)
	}, func(sum *string, value string) {
		*sum = *sum + value
	}, concurrent.UnorderedReduce)

	fmt.Println(ordered, unordered) // 123456 142536
}

About

Simple MapReduce on Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published