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?addamsson
07/14/2019, 4:26 PMPersistentCollection
and PersistentMap
?addamsson
07/14/2019, 4:26 PMaddamsson
07/14/2019, 4:26 PMsimon.vergauwen
07/14/2019, 4:26 PMsimon.vergauwen
07/14/2019, 4:27 PMaddamsson
07/14/2019, 4:27 PMaddamsson
07/14/2019, 4:27 PMaddamsson
07/14/2019, 4:28 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>
simon.vergauwen
07/14/2019, 4:40 PMKind<ForList, A>
where you can apply a type to ForList
using the Kind
interface.simon.vergauwen
07/14/2019, 4:41 PMMap<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
.simon.vergauwen
07/14/2019, 4:42 PMsimon.vergauwen
07/14/2019, 4:52 PMIs 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
addamsson
07/14/2019, 6:57 PMaddamsson
07/14/2019, 6:57 PMremove
operationaddamsson
07/14/2019, 7:00 PMForMap
look like?addamsson
07/14/2019, 8:04 PMMonoid<PersistentCollection<E>>
, Foldable<E>
, Functor<E>
and FunctorFilter<E>
?addamsson
07/14/2019, 8:04 PMaddamsson
07/14/2019, 8:04 PMinterface PersistentCollection<E> : Monoid<PersistentCollection<E>>, Foldable<E>, Functor<E>, FunctorFilter<E>
addamsson
07/14/2019, 8:05 PMKind
or an Eval
raulraja
07/14/2019, 9:26 PMraulraja
07/14/2019, 9:27 PMremove
applied to a concrete type?addamsson
07/14/2019, 9:33 PMaddamsson
07/14/2019, 9:33 PMaddamsson
07/14/2019, 9:34 PMfun remove(element: E): PersistentCollection<E>
addamsson
07/14/2019, 9:35 PMaddamsson
07/14/2019, 9:36 PMPersistentCollection<E>.fun remove(element: E): PersistentCollection<E>
addamsson
07/14/2019, 9:36 PMremove
function for each collection typeaddamsson
07/14/2019, 9:36 PMSet
and List
for now)addamsson
07/14/2019, 9:38 PMaddamsson
07/14/2019, 9:38 PMKind
is used for?addamsson
07/14/2019, 9:38 PMKind<ForPeristentCollection, E>
?addamsson
07/14/2019, 9:44 PMPersistentCollection
addamsson
07/14/2019, 9:44 PMPersistentSet
or a PersistentList
addamsson
07/14/2019, 9:44 PMaddamsson
07/14/2019, 9:45 PMsimon.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.simon.vergauwen
07/14/2019, 10:22 PMPersistentSetOf<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.simon.vergauwen
07/14/2019, 10:26 PMFunctor
, 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 PMaddamsson
07/14/2019, 10:27 PMPersistentCollection
at allsimon.vergauwen
07/14/2019, 10:27 PMForPersistentList
and PersistentMapPartialOf<String>
.addamsson
07/14/2019, 10:28 PMaddamsson
07/14/2019, 10:28 PMsimon.vergauwen
07/14/2019, 10:28 PMaddamsson
07/14/2019, 10:28 PMaddamsson
07/14/2019, 10:29 PMsimon.vergauwen
07/14/2019, 10:29 PMaddamsson
07/14/2019, 10:32 PMaddamsson
07/14/2019, 10:32 PMaddamsson
07/15/2019, 7:39 AMaddamsson
07/15/2019, 7:59 AMaddamsson
07/15/2019, 7:59 AMaddamsson
07/15/2019, 7:59 AMaddamsson
07/15/2019, 9:35 AMraulraja
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 AMaddamsson
07/15/2019, 11:55 AMaddamsson
07/15/2019, 11:56 AMaddamsson
07/15/2019, 11:56 AMaddamsson
07/15/2019, 11:56 AMaddamsson
07/15/2019, 11:56 AMaddamsson
07/15/2019, 12:06 PMraulraja
07/15/2019, 12:49 PMraulraja
07/15/2019, 12:50 PMraulraja
07/15/2019, 12:51 PMaddamsson
07/15/2019, 12:57 PMaddamsson
07/15/2019, 12:58 PMaddamsson
07/15/2019, 1:00 PMaddamsson
07/15/2019, 1:01 PMaddamsson
07/15/2019, 1:01 PM