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

     1  package loopexamples
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/m4gshm/gollections/loop"
     9  	"github.com/m4gshm/gollections/predicate/exclude"
    10  	"github.com/m4gshm/gollections/predicate/one"
    11  )
    12  
    13  func Test_OneOf(t *testing.T) {
    14  
    15  	var f1 = loop.Filter(loop.Of(1, 3, 5, 7, 9, 11), one.Of(1, 7).Or(one.Of(11))).Slice() //[]int{1, 7, 11}
    16  	var f2 = loop.Filter(loop.Of(1, 3, 5, 7, 9, 11), exclude.All(1, 7, 11)).Slice()       //[]int{3, 5, 9}
    17  
    18  	assert.Equal(t, []int{1, 7, 11}, f1)
    19  	assert.Equal(t, []int{3, 5, 9}, f2)
    20  }