# KeepIf and CountIf for types other than number

Currently KeepIf and CountIf seem to be limited to expressions of numbers, and thus lists of numbers. Sometimes one would like to filter a list of points or even a list of lists (e. g. based on their first element).

This can be worked around (but I don't see why the restriction is imposed): you can create a list with Sequence in which the elements corresponding to the elements original list are the index of the element if the condition is true for the original element and 0 otherwise. Then you can keep the positive elements (i. e. the indexes of the elements for which the condition holds) with KeepIf and create the list of the elements of the original list with these indexes with another Sequence command.

So I propose that the condition can be any boolean expression of the element in question. I also propose that the variable is not compulsorily x but is given as an other parameter, just as in the Sequence command: the current implementation is problematic if one wants to embed KeepIf and/or CountIf commands in each other. An example when that would be practical: keep the numbers k in a list for which the number of occurrences of k in the list is exactly k.

I have read the many proposed features that 'gd' has suggested; the list is long and will take a long time to implement all of them. However, since KeepIf and CountIf are already defined for number objects and GGB is written in Java, it may be possible to EXTEND the functions to other objects fairly easily.

gd, I am sure that the development teams would need extensive assistance in programming all the other features.

Thanks,

Tony

I know that the proposals related to scripting would need a long time to implement. I suggest them as possible (and in my opinion good) long-term plans.

You can do this using the Sequence, Sum and RemoveUndefined commands

eg:

https://ggbm.at/540813

Thanks, that's shorter than my workaround.

Loading...Comments have been locked on this page!