addamsson
07/14/2019, 4:25 PMPersistentCollection
+ PersistentMap
only with Semigroup
, Monoid
, Foldable
, Functor
and FunctorFilter
.
There is one question though: Implementing removal with FunctorFilter
isn't going to be ineffective? I mean it is O(n)
vs O(log n)
or even O(1)
in some of the cases. Is there a typeclass for explicit removal instead of filtering?PersistentCollection
and PersistentMap
?simon.vergauwen
07/14/2019, 4:26 PMaddamsson
07/14/2019, 4:27 PMsimon.vergauwen
07/14/2019, 4:39 PMList<A>
takes 1 type parameter to become a real type. i.e. List + Int = List<Int>.
When we take Functor
it takes a type that takes 1 type parameter, or it takes a Higher kind type of rank 1 (* -> *).
This is so we can define fun <A, B> List<B>.map(f: (A) -> B): List<B>
, here we require 2 generic types in the function and apply them to the type of Functor. Functor<ForList>
Kind<ForList, A>
where you can apply a type to ForList
using the Kind
interface.Map<A, B>
takes 2 parameters, so we need to somehow turn it into a type that only takes 1 parameter so we can use it with Functor
.
Again you can do this with Kind
so let’s say we’d want to use String
as A
or key in the map, we do Kind<ForMap, String>
. This still takes another kind parameter before we can consider the type a Map
.Is there a typeclass for explicit removal instead of filtering?I had to double check but I am not sure if we currently have something like that. It’s a pattern available in
Optics
by using At
. https://github.com/arrow-kt/arrow/blob/master/modules/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/At.kt#L128addamsson
07/14/2019, 6:57 PMAt
remove
operationForMap
look like?Monoid<PersistentCollection<E>>
, Foldable<E>
, Functor<E>
and FunctorFilter<E>
?interface PersistentCollection<E> : Monoid<PersistentCollection<E>>, Foldable<E>, Functor<E>, FunctorFilter<E>
Kind
or an Eval
raulraja
07/14/2019, 9:26 PMremove
applied to a concrete type?addamsson
07/14/2019, 9:33 PMfun remove(element: E): PersistentCollection<E>
PersistentCollection<E>.fun remove(element: E): PersistentCollection<E>
remove
function for each collection typeSet
and List
for now)Kind
is used for?Kind<ForPeristentCollection, E>
?PersistentCollection
PersistentSet
or a PersistentList
simon.vergauwen
07/14/2019, 10:19 PMForPersistentSet
and ForPersistentList
, then you can apply them to a type parameter using interface Kind<F, A>
. This results in typealias PersistentSetOf<A> = Kind<ForPersistentSet, A>
, and then you should inheret from the typealias @higherkind interface PersistentSet<A> : PersistentSetOf<A>
. The annotation will generate all the boilerplate for you so you only have to inherit from the typealias and add the annotation.PersistentSetOf<A>
to PersistentSet<A>
you have to call fix()
because the compiler currently doesn't understand higher kinded types so we have to write some boilerplate. This small piece of boilerplate will disappear when we release the compiler plugin for kinds.Functor
, object PersistentSetFunctor : Functor<ForPersistentSet> {...}
. When we fill in all the generics for map it looks like this fun <A> PersistentSetOf<A>.map(f: (A) -> B): PersistentSet<A>
.addamsson
07/14/2019, 10:27 PMPersistentCollection
at allsimon.vergauwen
07/14/2019, 10:27 PMForPersistentList
and PersistentMapPartialOf<String>
.addamsson
07/14/2019, 10:28 PMsimon.vergauwen
07/14/2019, 10:28 PMaddamsson
07/14/2019, 10:28 PMsimon.vergauwen
07/14/2019, 10:29 PMaddamsson
07/14/2019, 10:32 PMraulraja
07/15/2019, 11:39 AMif I’m using the Arrow setup I’ll have to replicate it in my projectCan you elaborate in what you mean by that?
addamsson
07/15/2019, 11:55 AMraulraja
07/15/2019, 12:49 PMaddamsson
07/15/2019, 12:57 PM