0

I have a list in which objects gets added, modified and removed very frequently with asynchronous calls (Dart).

I don't want to update object by index to ensure that the target object is only modified.

I tried this

class Foo(){
    prop1;
    prop2;
}

class Bar(){
    List<Foo> list = List();

    Bar(){
        this.list = [foo1, foo2, foo3,];
    }

    updateList(someObj) async {
        this.list.asMap().entries.forEach(entry){
            if (entry.value.prop1 == someObj.prop1){
                this.list[entry.key].prop2 = someObj.prop2  
                // update object prop by index is working as of now, but 
               // multiple update calls can lead to update of wrong object 
            }
        }
    }
    
    addObj(someObj) async {
       ...
    }
    
    deleteObj(someObj) async {
       ...
    }
}

// calling function (async or without async) 
doSomething(){ 
   barObj.updateList(someObj); // this is a async function
   otherFunc(); // this line is not blocked
}

Can any one suggest me better way to update object in a list ensuring same object is updated?


You can use circshift to do that:

X=imread('peppers.png');
dx = -200;
dy = 100;
Y = circshift(X, [dy dx 0]);
imshow(Y)

enter image description here

As an additional note about your code, use rgb2gray for converting images to grayscale.

4

0 回答 0