regarding Scala types
Apr. 6th, 2021 07:05 pmHad a discussion yesterday. Basically, about this equality:
No surprise, just making sure that it behaves as expected. Two projections are equal.
scala> "abc": Iterable[Char] val res0: Iterable[Char] = abc scala> List('a', 'b', 'c'): Iterable[Char] val res1: Iterable[Char] = List(a, b, c) scala> res0 == res1 val res2: Boolean = true
No surprise, just making sure that it behaves as expected. Two projections are equal.
с ужасом обнаружил...
Aug. 1st, 2020 01:34 pmЧто в ScalaZ ноль тестов для
OptionT
.
Я им когда-то навалял тест для finger trees, ну и. Короче, за столько лет если не сбацали, так и все уже, наверно.
Хм.
Это я хотел поэкспериментировать. Потому что не совсем понимаю причин коммутирования (и могу привести простой контрпример).
Пошел смотреть, как оно в typelevel/cats.
In short. Have to use cats. Probably not.
Will take a look at ZIO later.пара заметок
Jun. 27th, 2020 07:48 amНочью приходил енот, помыл кошкину миску. Почему этого енота не записала камера, непонятно.
Regarding type parameters and member types. Say, you have
We can as well view both as binary relations between types (or profunctors, if we go to categories). One is an inverse of another.
So when you choose which one to prefer, mind the meaning of it.
(inspired by Compall's blog from 2015.
Regarding type parameters and member types. Say, you have
trait T[X]{}
. With a certain caveat, you may view it as a functor. If you have trait T { type X }
. We have a partial mapping that, given a type, produces X
(or not).We can as well view both as binary relations between types (or profunctors, if we go to categories). One is an inverse of another.
So when you choose which one to prefer, mind the meaning of it.
(inspired by Compall's blog from 2015.
seems like a compiler bug
May. 11th, 2020 10:02 amWelcome to Scala 2.12.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92). Type in expressions for evaluation. Or try :help. scala> def f(x: Int) = 10 + x -> "ok" f: (x: Int)(Int, String) scala> f(10) res0: (Int, String) = (20,ok) scala> def g(x: Int) = 20 + x → "oops":11: error: overloaded method value + with alternatives: (x: Double)Double (x: Float)Float (x: Long)Long (x: Int)Int (x: Char)Int (x: Short)Int (x: Byte)Int (x: String)String cannot be applied to ((Int, String)) def g(x: Int) = 20 + x → "oops" ^
ok, done with Lawvere-Tierney topologies
Mar. 29th, 2020 03:07 pmhttps://github.com/vpatryshev/Categories/blob/master/src/main/scala/math/cat/topos/LawvereTopology.scala
That's in Grothendieck toposes, of course.
That's in Grothendieck toposes, of course.
Netflix problem
Mar. 25th, 2020 06:23 pmobject model { type MovieId = Long type UserId = Long case class View(userId: UserId, movieId: MovieId) } import model._ object Solution extends App { def diverseMovies(views: Seq[View], numMovie: Int): Set[MovieId] = { def choose(except: Set[UserId] = Set.empty): MovieId = { views.collect { case view if !except(view.userId) => view }. groupBy(_.movieId).mapValues(_.size).maxBy(_._2)._1 } def viewersOf(movie: MovieId) = views.filter(_.movieId equals movie).map(_.userId).toSet val result: (List[MovieId], Set[UserId]) = ((List.empty[MovieId], Set.empty[UserId])/:(1 to numMovie)) ({ case ((movies: List[MovieId], ignoredUsers: Set[MovieId]), _) => { val movie = choose(ignoredUsers) (movie::movies, ignoredUsers ++ viewersOf(movie)) } }) result._1.toSet } }