mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[stdlib] List.__eq__ and List.__ne__ for Rhs_t:ComparableCollectionElement

Open rd4com opened this issue 9 months ago • 1 comments

Hello,

here is an implementation of List.__eq__ and List.__ne__ that makes it possible to do:

var x = List(1,2,3)
var y = List(1,2,3)
if x == y: print("same values")
if x != y: print("not same values")

 

One of the downside is that part of the implementation is done with constrained,

this is not ideal because users won't be aware of some errors until m̀ojo build main.mojo shows the constrained failed.

But it is necessary to have the constrained because rhs could be a list[Bool] and self a list[Int], for example.

rd4com avatar May 17 '24 09:05 rd4com