what could possibly cause a filter operation not t...
# getting-started
o
what could possibly cause a filter operation not to be run? I mean the list is there and it gets successfully sorted by name through a comparator I have set
a
we need some code 😉
o
nah it is running, but it seems like it isnt removing them items to keep the ones I filter by, I see them later in the views
Copy code
subModels.filter{it.active}.sortedWith(compareBy({it.name }))
a
and the output of that expression is a filtered + sorted list of
subModels
?
o
supposedly yes
this is what I expect to happen, I mean
a
so my guess would be that you reuse the old list instead of the filtered+sorted list, but I cant tell without more code
o
as I suspected, I just compared size of list before and after this op
same
a
so all of the items are
active
?
o
all of them
have
an active field and it can either be true or false, ive logged them
this is the whole piece of code
Copy code
database.carModelsDao()
                .insert(models.filter {
                    it.active }.sortedWith(compareBy({
                    it.name })))
it should work as is
a
first make sure that its really this expression thats the culprit. introduce a local val and check whether the filter works
o
I had logs inside the filter operations
to know they’re being hit
a
are they begin hit?
o
yes
with false sometimes and true sometimes, just as the real data
and the comparison also
a
and the output of
filter
is exactly the same as the input?
o
this is the main entry point for the data existing altogether, all other places in the code grab from what was inserted in this piece of code to the DB
Im attaching a
.size()
to the end of the filter/compare now
aha, at the end of the filter op, a size() produces a much smaller number
the filtering is happening
e
I think you assumed the filtering happen to the original list?
o
god damn it
the endpoint is mistaken!
and im sitting here looking at the code I’ve filtered a million times elsewhere… lol
excuse me