https://kotlinlang.org logo
Title
o

oday

12/13/2018, 5:44 PM
the idea is there though @karelpeeters?
k

karelpeeters

12/13/2018, 5:48 PM
If a filter isn't active shouldn't it return
true
?
o

oday

12/13/2018, 5:49 PM
what I mean is that it should skip over it, true would mean that it did match that criteria
oh
k

karelpeeters

12/13/2018, 5:49 PM
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

oday

12/13/2018, 5:50 PM
there’s no position in
all
and arraylist because the method im calling takes an arraylist, not necessary
k

karelpeeters

12/13/2018, 5:51 PM
Then you should use
filterTo(ArrayList()) { ... }
. But what a weird method!
o

oday

12/13/2018, 5:51 PM
nah I can have it handle a list of course
just havent yet
k

karelpeeters

12/13/2018, 5:51 PM
Why do need the position in
all
?
o

oday

12/13/2018, 5:52 PM
to be able to check if currentFilter is active
if (currentFilters[0].active)
need to know which one im referring to
k

karelpeeters

12/13/2018, 5:53 PM
I'd do
originalListings.filter { listing -> currentFilters .all { (str, enabled) -> !enabled || (listing.tags != null && listing.tags.isNotEmpty() && listing.tags[0] != getString(str)) } }
And drop the
predicates
list.
o

oday

12/13/2018, 5:54 PM
inside each of the predicates
yea
what, that only handles 1 case
there are 5 filters
k

karelpeeters

12/13/2018, 5:56 PM
Ah I only looked at the first two and assumed everything else was the same pattern.
o

oday

12/13/2018, 5:57 PM
so predicate list is needed
k

karelpeeters

12/13/2018, 5:57 PM
Yeah but the handing of "being enabled" should not be manually handles when creating the list like this.
o

oday

12/13/2018, 5:57 PM
yea i can pass a position and do it when needed
k

karelpeeters

12/13/2018, 5:59 PM
Then I'd so somehting like this:
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

oday

12/13/2018, 6:00 PM
I actually went and created a MutableTriple 😆
when I tried this before
yea class would do
k

karelpeeters

12/13/2018, 6:01 PM
Pairs and triples are kind of shady, it's better to just make a class, it's so short in Kotlin.
o

oday

12/13/2018, 6:08 PM
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

arve

12/13/2018, 8:33 PM
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

oday

12/13/2018, 8:39 PM
I knew it!
i knew i could use any!
HA!
thanks!
i came here to say that i think any would work 😄
k

karelpeeters

12/13/2018, 8:47 PM
Are you sure you need
any
? An if with a bunch of conditions with
&&
->
all
, and
||
->
any
.
o

oday

12/13/2018, 8:49 PM
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

karelpeeters

12/13/2018, 8:50 PM
You require all active filters to match, right?
That's what my example code earlier did.
filters.all { !it.enabled || it.pred(listing)
o

oday

12/13/2018, 8:50 PM
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

karelpeeters

12/13/2018, 9:00 PM
That doesn't make sense, a filter removes stuff.
o

oday

12/13/2018, 9:01 PM
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

karelpeeters

12/13/2018, 9:02 PM
Call them matchers then or something.
o

oday

12/13/2018, 9:06 PM
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