Adding and updating objects?

Dec 1, 2011 at 8:17 PM
Edited Dec 2, 2011 at 4:46 AM

Is it possible to add/update/delete objects easily? I know this isn't really LINQ but more like EF. I think it could really be useful. Something like:

 

var jsonUsers = [
	{ "id": 1, "username": "john", "phone": "111-111-1111" },
    { "id": 2, "username": "jane", "phone": "222-222-2222" },
    { "id": 3, "username": "joe", "phone": "333-333-3333" }, 
    { "id": 4, "username": "jenny", "phone": "444-444-4444" }
]

var linqUsers = Enumerable.From(jsonUsers);
var user = linqUsers.FirstOrDefault(null, "$.id == 1");

if(user != null) {
	user.phone = "111-123-4567";
	linqUsers.Update("$.id == 1", user);
}

linqUsers.Add({ "id": 5, "username": "jeremy", "phone": "555-555-5555" });

linqUsers.Delete("$.id == 3");
Dec 2, 2011 at 4:48 AM

I created a fork to add this functionality and have submitted a pull request. thanks.

Coordinator
Dec 2, 2011 at 3:29 PM

Thank you.

It is nice.
However, it can not receive.
It is not LINQ that internal action is for Array.
I think  it make as a different class.
or plugin/binding file to Enumerable.prototype like linq.rx.js or linq.jquery.js.

But it is not good that CreateLambda touches it only from the inside.
Next linq.js(I am sorry to be late) will have Enumerable.Utils.createLambda/createEnumerable/createEnumerator.
I want you to wait for it.