imaps

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[K, V any](s2 iter.Seq2[K, V], filterFunc Filter2Func[K, V]) iter.Seq2[K, V]
Example
package main

import (
	"fmt"
	"maps"

	imaps "github.com/gomoni/it/imaps"
)

func main() {
	m := map[string]int{
		"bambino": 1,
		"junior":  11,
		"senior":  22,
	}
	s0 := maps.All(m)
	s1 := imaps.Filter(s0, func(_ string, v int) bool { return v >= 18 })
	result := maps.Collect(s1)
	fmt.Println(result)
}
Output:

map[senior:22]

func Map

func Map[K, V, K2, V2 any](s2 iter.Seq2[K, V], mapFunc Map2Func[K, V, K2, V2]) iter.Seq2[K2, V2]
Example
package main

import (
	"fmt"
	"maps"

	imaps "github.com/gomoni/it/imaps"
)

func main() {
	m := map[string]int{
		"bambino": 1,
		"junior":  11,
		"senior":  22,
	}
	s0 := maps.All(m)
	s1 := imaps.Map(s0, func(s string, _ int) (string, int) { return s, len(s) })
	result := maps.Collect(s1)
	fmt.Println(result)
}
Output:

map[bambino:7 junior:6 senior:6]

Types

type Filter2Func

type Filter2Func[K, V any] func(K, V) bool

Filter2Func is a predicate for type K, V

type Map2Func

type Map2Func[K, V, K2, V2 any] func(K, V) (K2, V2)

Map2Func maps the K, V -> K2, V2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL