Skip to content

Commit

Permalink
feat: Implement funk.Partition
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvantuan2391996 committed Aug 8, 2023
1 parent c570b99 commit 62fe2df
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ func Test_partition_valid_string(t *testing.T) {
}

func Test_partition_valid_struct(t *testing.T) {
type User struct {
Name string
Age int
}
result := Partition([]*User{{Name: "Kakalot", Age: 26}, {Name: "Vegeta", Age: 27}, {Name: "Trunk", Age: 10}}, func(n *User) bool {
result := Partition([]*Foo{
{
FirstName: "Kakalot",
Age: 26,
},
{
FirstName: "Vegeta",
Age: 27,
},
{
FirstName: "Trunk",
Age: 10,
},
}, func(n *Foo) bool {
return n.Age%2 == 0
})

assert.Equal(t, [][]*User{{{Name: "Kakalot", Age: 26}, {Name: "Trunk", Age: 10}}, {{Name: "Vegeta", Age: 27}}}, result)
assert.Equal(t, [][]*Foo{{{FirstName: "Kakalot", Age: 26}, {FirstName: "Trunk", Age: 10}}, {{FirstName: "Vegeta", Age: 27}}}, result)
}

0 comments on commit 62fe2df

Please sign in to comment.