ETS table `select_take`

I’ve been in need for an ets:select_take function. Currently a select of all keys for matching elements followed by a take is required since select_delete returns only the number of deleted elements. Could also do a select/match followed by a delete but that would mean some updates would technically succeed on an element but not be part of what was selected.

Curious if anyone else has encountered need for this and if anyone knows what an implementation would look like.

3 Likes

I only glanced at some of code on my phone, and I might firing off too quick here… but you could either set up the implementation of select_delete to accumulate the terms that are simply freed in the current implementation (i.e., have an accumulator in the state that is either Uint or an Eterm based on an extra argument passed in), or copy / pasta and modify :slight_smile:

I think this would be a nice thing to have. I want to say I needed something like this in a previous project, but I’d have to go back and look at what I was doing (some type of queue iirc).

1 Like

I wish there was just 1 forum for BEAM :). Wondering if I should cross-post this to Elixir forum to see if others also think it is useful.

1 Like

You probably should, there seems to be a summer lull here :slight_smile:

As for a single forum, it’s an interesting thought, maybe another conversation should be spun up around it?

Oh right… Europeans.

2 Likes

I guess I’ll still crosspost and if it gets any traction over there I can use it as ammo for why we should consolidate :slight_smile:

1 Like