Skip to content

Commit

Permalink
Remove added
Browse files Browse the repository at this point in the history
  • Loading branch information
martindrlik committed Jun 22, 2024
1 parent 607da0c commit bfecc5e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/martindrlik/rex

go 1.22.1
go 1.22.4

require golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
require golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
go 1.22.1
go 1.22.4

use .
10 changes: 4 additions & 6 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
11 changes: 11 additions & 0 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ func (t *Table) Add(tuples ...map[string]any) *Table {
return t
}

// Remove returns new table without given tuple.
func (t *Table) Remove(tuple map[string]any) *Table {
x := New()
for _, t := range t.tuples {
if !T(t).Equals(tuple) {
x.Add(t)
}
}
return x
}

func (t *Table) SchemaOrder() []string {
if len(t.schema) != 0 {
return t.schema
Expand Down
14 changes: 14 additions & 0 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ func ExampleTable_Add() {
// ┗━━━━━━━━━━━━┷━━━━━━┛
}

func ExampleTable_Remove() {
theMatrix := movie("The Matrix", 1999)
movies := table.New().Add(theMatrix, movie("Dune: Part Two", 2023))
movies = movies.Remove(theMatrix)
fmt.Println(box.Table([]string{"title", "year"}, movies.Tuples()...))

// Output:
// ┏━━━━━━━━━━━━━━━━┯━━━━━━┓
// ┃ title │ year ┃
// ┠────────────────┼──────┨
// ┃ Dune: Part Two │ 2023 ┃
// ┗━━━━━━━━━━━━━━━━┷━━━━━━┛
}

func TestContains(t *testing.T) {
matrixMovie := movie("The Matrix", 1999)
movies := table.New().Add(matrixMovie)
Expand Down

0 comments on commit bfecc5e

Please sign in to comment.