Skip to content

JoaoPaulo-creator/gosimpleiterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go simple iterator

About

Go simple iterator it’s a package that contains simple functions to iterate over slices of basicaly any type. I built this, because I think the builtin package iter over complicated and hard to read, specially in my usecases

Examples

Map

p := Person{
		Name:  "Joao",
		Age:   27,
		Email: "[email protected]",
		Adress: []PersonAddress{
			{
				StreetName:    "Rua Dos bobos",
				StreetNumber:  "A27",
				Neighbourhood: "caraio",
				AddressType:   "home",
			},
			{
				StreetName:    "Avenue Abc",
				StreetNumber:  "1234",
				Neighbourhood: "Aehoo",
				AddressType:   "work",
			},
			{
				StreetName:    "Acacia Avenue",
				StreetNumber:  "782",
				Neighbourhood: "London",
				AddressType:   "bar",
			},
		},
	}

addreeses := MapT(func(n PersonAddress) string {
		return n.AddressType
}, p.Adress)

fmt.Printf("Addresses list: %s\n", addreeses)

Filter

p := Person{
		Adress: []PersonAddress{
			{
				StreetName:    "Rua Dos bobos",
				StreetNumber:  "A27",
				Neighbourhood: "caraio",
				AddressType:   "home",
			},
			{
				StreetName:    "Avenue Abc",
				StreetNumber:  "1234",
				Neighbourhood: "Aehoo",
				AddressType:   "work",
			},
			{
				StreetName:    "Rua teste",
				StreetNumber:  "1234",
				Neighbourhood: "Downtown",
				AddressType:   "work",
			},
			{
				StreetName:    "Acacia Avenue",
				StreetNumber:  "782",
				Neighbourhood: "London",
				AddressType:   "bar",
			},
		},
}

filteredList := Filter(func(n PersonAddress) bool {
		return strings.Contains(n.AddressType, "work")
}, p.Adress)

fmt.Println(filteredList)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages