the idea is there though <@U5UU34LPK>?
# getting-started
o
the idea is there though @karelpeeters?
k
If a filter isn't active shouldn't it return
true
?
o
what I mean is that it should skip over it, true would mean that it did match that criteria
oh
k
Right
I'm also confused as to why you need two arrays, one with strings and one with predicated based on them. Just handle the disabled-ness in the call to
all
?
And then why the
ArrayList
at the end?
o
there’s no position in
all
and arraylist because the method im calling takes an arraylist, not necessary
k
Then you should use
filterTo(ArrayList()) { ... }
. But what a weird method!
o
nah I can have it handle a list of course
just havent yet
k
Why do need the position in
all
?
o
to be able to check if currentFilter is active
if (currentFilters[0].active)
need to know which one im referring to
k
I'd do
originalListings.filter { listing -> currentFilters .all { (str, enabled) -> !enabled || (listing.tags != null && listing.tags.isNotEmpty() && listing.tags[0] != getString(str)) } }
o
inside each of the predicates
k
And drop the
predicates
list.
o
yea
what, that only handles 1 case
there are 5 filters
k
Ah I only looked at the first two and assumed everything else was the same pattern.
o
so predicate list is needed
k
Yeah but the handing of "being enabled" should not be manually handles when creating the list like this.
o
yea i can pass a position and do it when needed
k
Then I'd so somehting like this:
Copy code
class Filter(val str: String, val pred: (CarLeasingResponse) -> Boolean, var enabled: Boolean)

val filters = listOf(Filter(...), Filter(...))

originalListings.filter { listing -> filters.all { !it.enabled || it.pred(listing) } }
o
I actually went and created a MutableTriple 😆
when I tried this before
yea class would do
k
Pairs and triples are kind of shady, it's better to just make a class, it's so short in Kotlin.
o
that is beautiful actually
i think the misunderstanding of returning True in filter was my issue, I thought the inverse
and the overly complicated design 🙂
👍 1
I seem to be at a loss here, I’m unable to express the idea of “matches this active filter, or that active filter or that active filter” together, right now i match each 1 by itself
like if I have cars that have property X and property Y and property F, if I say filter X and filter Y are ON, i want to see cars matching both these predicates
i think i should get rid of the
all
on currentFilters, and just place the predicates in a long if statement with ORs for each predicate
a
you just said two opposite statements 🤔
“matches this active filter, or that active filter or that active filter”
vs
filter X and filter Y are ON, i want to see cars matching both these predicates
Are you sure you don't mean
filter X and filter Y are ON, i want to see cars matching at least one of these predicates
? If that's the case you might be looking for
Collections.any { predicate}
(as opposed to
all
)?
o
I knew it!
i knew i could use any!
HA!
thanks!
i came here to say that i think any would work 😄
k
Are you sure you need
any
? An if with a bunch of conditions with
&&
->
all
, and
||
->
any
.
o
any isnt doing anything anyways, i have no idea why, it’s clear that i want to return true whenever an item in the current filters is active and its predicate returns true
ill debug it actually, but with if’s i dont know if you can achieve this cleanly
k
You require all active filters to match, right?
That's what my example code earlier did.
filters.all { !it.enabled || it.pred(listing)
o
that’s how it was
that only does 1 type of filter at a time
if a certain objects content match 2 of the filters, i want to include those as well
then im doing something wrong
when im running it, i can never reach a number higher than what i first started with
if I filter for something and get 30 results, it can never grow, only shrinks
its not adding them or im displaying them immediately or something
yea there’s something about the problem im not undersatnding, thanks for the help so far really!
for example if I have all filters on, all the list should be shown
k
That doesn't make sense, a filter removes stuff.
o
exactly my thoughts in the beginning, this is then called something else
i argued when I heard about it but I am checking how it’s done in another platform, same software as im making, that’s how it behaves
k
Call them matchers then or something.
o
that’s what i thought from the begining, it’s fucking insane what they’re describing, the more filters you have the closer you are to the original list!!
they were wrong, I am not insane 🙂
👍 1
turns out indeed that it was just matching, a very weird way of matching, totally insane, all just for the issue of not having to show an empty result when 2 of the criteria conflict, instead of fixing what the criteria is