Questions tagged [remove-if]

Common Lisp 'remove-if' function.

Common Lisp 'remove-if' function.

It's signature is:

remove-if test sequence &key from-end start end count key => result-sequence

CLHS: remove-if

201 questions
50
votes
4 answers

std::remove_if - lambda, not removing anything from the collection

Ok, I expect I've made a dumb mistake here. I have a list of DisplayDevice3d and each DisplayDevice3d contains a list of DisplayMode3d. I want to remove all items from the list of DisplayDevice3d that don't have any DisplayMode3d's. I'm trying to…
Robinson
  • 9,666
  • 16
  • 71
  • 115
38
votes
1 answer

Remove object from has_many but don't delete the original record in Rails?

I have this: Post.paragraphs << new_paragraph And I need to remove paragraph by id = 3, so the following deletes the record completely: Post.paragraphs.find(paragraph_id).destroy # or Post.paragraphs.find(paragraph_id).delete I just need to remove…
valk
  • 9,363
  • 12
  • 59
  • 79
32
votes
3 answers

Remove Elements from an Unordered Map Fulfilling a Predicate

I want to remove elements (histogram bins) from an std::unordered_map (histogram) that fulfills a predictate (histogram bins having zero count) given as a lambda expression as follows std::remove_if(begin(m_map), end(m_map), [](const Bin & bin) {…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
21
votes
3 answers

Replace/Remove characters that do not match the Regular Expression (.NET)

I have a regular expression to validate a string. But now I want to remove all the characters that do not match my regular expression. E.g. regExpression = @"^([\w\'\-\+])" text = "This is a sample text with some invalid characters…
tif
  • 1,109
  • 2
  • 12
  • 32
21
votes
7 answers

What is wrong with `std::set`?

In the other topic I was trying to solve this problem. The problem was to remove duplicate characters from a std::string. std::string s= "saaangeetha"; Since the order was not important, so I sorted s first, and then used std::unique and finally…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
18
votes
4 answers

C++ Operator () parenthesis overloading

I recently asked a question about removing items from a vector. Well, the solution I got works, but I don't understand it - and I cannot find any documentation explaining it. struct RemoveBlockedHost { RemoveBlockedHost(const std::string& s):…
FurryHead
  • 1,479
  • 3
  • 16
  • 19
14
votes
4 answers

Removing by index from a C++ vector using remove_if

We can use remove_if in C++ to remove elements from a vector in linear time based on a predicate that operates on the elements. bool condition(double d) {...} vector data = ... std::remove_if (data.begin(), data.end(), condition); What if…
donnyton
  • 5,874
  • 9
  • 42
  • 60
12
votes
2 answers

Filter function in Elisp

Is there equivalent of higher-order function filter in Emacs Lisp? Like function from python or Javascript. (filter-equivalent (lambda (n) (= (% n 2) 0)) '(1 2 3 4 5 6 7 8)) ==> (2 4 6 8)
jcubic
  • 61,973
  • 54
  • 229
  • 402
11
votes
2 answers

Why can't I remove a string from a std::set with std::remove_if?

Possible Duplicate: remove_if equivalent for std::map I have a set of strings: set strings; // ... I wish to remove strings according to a predicate, e.g.: std::remove_if ( strings.begin(), strings.end(), []( const wstring &s ) -> bool…
Benj
  • 31,668
  • 17
  • 78
  • 127
10
votes
4 answers

g++ string remove_if error

Here's the code: #include #include #include using namespace std; int main() { string word=""; getline(cin,word); word.erase(remove_if(word.begin(), word.end(), isspace), word.end()); …
Richard
  • 5,840
  • 36
  • 123
  • 208
10
votes
5 answers

Pass additional arguments to remove_if

I would like to remove elements from a vector using remove_if function but limiting the erasing to N elements. Example: // predicate function that determines if a value is an odd number. bool IsOdd (int i) { if (we deleted more than deleteLimit) …
dynamic
  • 46,985
  • 55
  • 154
  • 231
9
votes
3 answers

Remove Link on scroll

In my application I have 4 links with different IDs and 4 DIV with same ID as each link (I use them for anchor-jumping). My current code: One
Rubioli
  • 685
  • 6
  • 34
9
votes
6 answers

How to check if element has HTML in it before removing? jQuery

in a function I need to check if a (div, span, p) contains any .html elements in it before attempting to remove the html and add in new content. Not sure how to do this... I tried this, but not working: // HERE below I tried to do a check to see if…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
7
votes
1 answer

Groovy remove null elements from a map

I am getting a map in my method from another server and I have some null values, I wanted to remove those ones, because I am struggling with those values in the following process: My map looks something like: I had done the next code, but without…
rasilvap
  • 1,771
  • 3
  • 31
  • 70
6
votes
3 answers

Turning remove_if into remove_not_if

How can I reverse a predicate's return value, and remove the elements that return false instead of true? Here is my code: headerList.remove_if(FindName(name)); (please ignore lack of erase) with FindName a simple functor: struct FindName { …
DanDan
  • 10,462
  • 8
  • 53
  • 69
1
2 3
13 14