and here is my implementation in `FunctorFilter`: ...
# arrow-contributors
t
and here is my implementation in `FunctorFilter`:
Copy code
. /**
   * Apply a filter to a structure such that the output structure contains all instances of specified class.
   */
  @Suppress("UNCHECKED_CAST")
  fun <A, B> Kind<F, A>.filterIsInstance(klass: Class<B>): Kind<F, B> =
    filterMap { a -> if(klass.isInstance(a)) Some(a as B) else None }
i
@pakoito is that your intended function ?
a
shouldn't it be a kotlin's KClass instead?
i
How does filterIsInstance look like in the stdlib?
t
Here it is
Copy code
/**
 * Returns a list containing all elements that are instances of specified class.
 */
public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
    return filterIsInstanceTo(ArrayList<R>(), klass)
}
and
Copy code
/**
 * Appends all elements that are instances of specified class to the given [destination].
 */
public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
    @Suppress("UNCHECKED_CAST")
    for (element in this) if (klass.isInstance(element)) destination.add(element as R)
    return destination
}
p
I'm with @aballano, why not KClass?
for Java classes too, it seems
(?)
I'm surprised it's not inline + reified, I'm sure I'd seen
filterIsInstance<Bla>()
t
I think
filterIsInstance
should be the same interface with the
filterIsInstance
in stdlib
p
take a Kind and returns a Kind
no implicit list conversion
nah I don't like the stdib one, too much runtime magic
we have filter and filterMap for this
I like your initial one
t
I'm confused now 😄 what should I change in my implementation? Switch to KClass?
i
dont use the magic in the stdlib
p
Copy code
/**
   * Apply a filter to a structure such that the output structure contains all instances of specified class.
   */
  @Suppress("UNCHECKED_CAST")
  fun <A, B> Kind<F, A>.filterIsInstance(klass: Class<B>): Kind<F, B> =
    filterMap { a -> if(klass.isInstance(a)) Some(a as B) else None }
this works
now my question is, whether klass should be Class or KClass, and if you could test with a Java file to see which one works
as a test 😄
a
but the above doesn't work for him it seems, the generated extension functions are missing the right Class import
😱 1
i
Maybe a refresh would do it
t
I tried to clean build but it didn't work