@@ -18,6 +18,7 @@ import (
1818 "context"
1919 "encoding/base64"
2020 "errors"
21+
2122 "github.com/atomix/api/proto/atomix/headers"
2223 api "github.com/atomix/api/proto/atomix/list"
2324 "github.com/atomix/go-client/pkg/client/primitive"
@@ -58,6 +59,9 @@ type List interface {
5859 // Len gets the length of the list
5960 Len (ctx context.Context ) (int , error )
6061
62+ // Contains checks whether the list contains a value
63+ Contains (ctx context.Context , value []byte ) (bool , error )
64+
6165 // Slice returns a slice of the list from the given start index to the given end index
6266 Slice (ctx context.Context , from int , to int ) (List , error )
6367
@@ -258,6 +262,25 @@ func (l *list) Remove(ctx context.Context, index int) ([]byte, error) {
258262 }
259263}
260264
265+ func (l * list ) Contains (ctx context.Context , value []byte ) (bool , error ) {
266+ response , err := l .instance .DoQuery (ctx , func (ctx context.Context , conn * grpc.ClientConn , header * headers.RequestHeader ) (* headers.ResponseHeader , interface {}, error ) {
267+ client := api .NewListServiceClient (conn )
268+ request := & api.ContainsRequest {
269+ Header : header ,
270+ Value : base64 .StdEncoding .EncodeToString (value ),
271+ }
272+ response , err := client .Contains (ctx , request )
273+ if err != nil {
274+ return nil , nil , err
275+ }
276+ return response .Header , response , nil
277+ })
278+ if err != nil {
279+ return false , err
280+ }
281+ return bool (response .(* api.ContainsResponse ).Contains ), nil
282+ }
283+
261284func (l * list ) Len (ctx context.Context ) (int , error ) {
262285 response , err := l .instance .DoQuery (ctx , func (ctx context.Context , conn * grpc.ClientConn , header * headers.RequestHeader ) (* headers.ResponseHeader , interface {}, error ) {
263286 client := api .NewListServiceClient (conn )
0 commit comments