github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/internal/examples/boilerplate/loop_shortcuts_test.go (about)

     1  package boilerplate
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/m4gshm/gollections/convert/as"
    10  	"github.com/m4gshm/gollections/loop"
    11  	"github.com/m4gshm/gollections/loop/group"
    12  	"github.com/m4gshm/gollections/slice"
    13  )
    14  
    15  func Test_Loop_schortcuts(t *testing.T) {
    16  
    17  	data := loop.Of("Bob", "Chris", "Alice")
    18  
    19  	lowers := loop.Convert(data, strings.ToLower)
    20  
    21  	var lengthMap map[int][]string = group.Of(lowers, func(name string) int { return len(name) }, as.Is[string]) // converting to map
    22  
    23  	assert.Equal(t, slice.Of("chris", "alice"), lengthMap[5])
    24  
    25  }