Skip to content
Permalink
Browse files

Update to Scala 2.12.10

  • Loading branch information
kiroco12 committed Nov 28, 2019
1 parent 9d83ddf commit 40d5eccd58fda8b3f961e7f1285c86b1590b0ff0
@@ -11,10 +11,8 @@ lazy val fetch = (project in file("."))
libraryDependencies ++= Seq(
dep("exercise-compiler"),
dep("definitions"),
%%("cats-core", V.cats),
%%("cats-effect", V.cats),
%%("fetch", V.fetch),
%%("fetch-debug", V.fetch),
"com.47deg" %% "fetch" % V.fetch,
"com.47deg" %% "fetch-debug" % V.fetch,
%%("shapeless", V.shapeless),
%%("scalatest", V.scalatest),
%%("scalacheck", V.scalacheck),
@@ -42,13 +42,12 @@ object ProjectPlugin extends AutoPlugin {
orgLicenseSetting := ApacheLicense,
scalaVersion := V.scala212,
scalaOrganization := "org.scala-lang",
scalacOptions := scalacCommonOptions ++ Seq("-Ypartial-unification"),
resolvers ++= Seq(
Resolver.mavenLocal,
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
scalacOptions := sbtorgpolicies.model.scalacCommonOptions,
scalacOptions := scalacCommonOptions ++ scalacLanguageOptions ++ Seq("-Ypartial-unification"),
headerLicense := Some(Custom(s"""| scala-exercises - ${name.value}
| Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
|
@@ -1,12 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 3.8.3 (29802) - http://www.bohemiancoding.com/sketch -->
<title>fetch</title>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="32px" height="32px" viewBox="0 0 48 48" version="1.1">
<!-- Generator: Sketch 55.2 (78181) - https://sketchapp.com -->
<title>navbar_brand</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="fetch" fill="#FFFFFF">
<path d="M27.5795724,10.2114804 C26.7152019,10.2114804 26.0118765,9.52564955 26.0118765,8.68277946 C26.0118765,7.83990937 26.7152019,7.15407855 27.5795724,7.15407855 C28.443943,7.15407855 29.1472684,7.83990937 29.1472684,8.68277946 C29.1472684,9.52564955 28.443943,10.2114804 27.5795724,10.2114804 L27.5795724,10.2114804 Z M15.7028504,26.1933535 C14.8391924,26.1933535 14.1351544,25.5075227 14.1351544,24.6646526 C14.1351544,23.8217825 14.8391924,23.1359517 15.7028504,23.1359517 C16.5672209,23.1359517 17.2712589,23.8217825 17.2712589,24.6646526 C17.2712589,25.5075227 16.5672209,26.1933535 15.7028504,26.1933535 L15.7028504,26.1933535 Z M6.94228029,10.5693353 C7.29287411,10.192719 7.55083135,9.74036254 7.69691211,9.23867069 L12.4263658,9.23867069 C12.8332542,10.6367372 14.1401425,11.6706949 15.7028504,11.6706949 C17.2662708,11.6706949 18.5731591,10.6367372 18.9800475,9.23867069 L24.2168646,9.23867069 C24.2852732,9.63265861 24.427791,9.9981571 24.6251781,10.3330816 L16.9463183,21.5655589 C16.560095,21.4175529 16.1425178,21.3293051 15.7028504,21.3293051 C15.2638955,21.3293051 14.8463183,21.4175529 14.460095,21.5655589 L12.868171,19.2370695 L6.94228029,10.5693353 Z M2.85273159,8.33534743 C2.85273159,7.49247734 3.55605701,6.80664653 4.42042755,6.80664653 C5.2847981,6.80664653 5.98812352,7.49247734 5.98812352,8.33534743 C5.98812352,9.17821752 5.2847981,9.86404834 4.42042755,9.86404834 C3.55605701,9.86404834 2.85273159,9.17821752 2.85273159,8.33534743 L2.85273159,8.33534743 Z M15.7028504,6.80664653 C16.5672209,6.80664653 17.2712589,7.49247734 17.2712589,8.33534743 C17.2712589,9.17821752 16.5672209,9.86404834 15.7028504,9.86404834 C14.8391924,9.86404834 14.1351544,9.17821752 14.1351544,8.33534743 C14.1351544,7.49247734 14.8391924,6.80664653 15.7028504,6.80664653 L15.7028504,6.80664653 Z M27.5795724,5.34743202 C26.1472684,5.34743202 24.9223278,6.2118429 24.4135392,7.43202417 L18.9800475,7.43202417 C18.5731591,6.03326284 17.2662708,5 15.7028504,5 C14.1401425,5 12.8332542,6.03326284 12.4263658,7.43202417 L7.69691211,7.43202417 C7.29002375,6.03326284 5.98384798,5 4.42042755,5 C2.53420428,5 1,6.4960423 1,8.33534743 C1,10.1746526 2.53420428,11.6706949 4.42042755,11.6706949 C4.75178147,11.6706949 5.06532067,11.6095468 5.36817102,11.5240785 L12.984323,22.664139 C12.5503563,23.2228097 12.2831354,23.9114199 12.2831354,24.6646526 C12.2831354,26.5039577 13.8173397,28 15.7028504,28 C17.5890736,28 19.1232779,26.5039577 19.1232779,24.6646526 C19.1232779,23.9114199 18.856057,23.2228097 18.4220903,22.664139 L25.9783848,11.6116314 C26.4579572,11.8624773 26.9980998,12.0181269 27.5795724,12.0181269 C29.4657957,12.0181269 31,10.5220846 31,8.68277946 C31,6.84347432 29.4657957,5.34743202 27.5795724,5.34743202 L27.5795724,5.34743202 Z" id="Fill-1"></path>
<g id="navbar_brand" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(6.000000, 3.000000)" stroke="#DD3D3D" stroke-width="2">
<path d="M17.9938,20.4764 L34.0018,11.2384" id="Stroke-17"/>
<path d="M1.9998,11.2344 L17.9938,2.0004" id="Stroke-19"/>
<path d="M1.9998,11.2344 L1.9998,29.7064" id="Stroke-21"/>
<path d="M1.9998,29.707 L17.9998,38.947" id="Stroke-23"/>
<path d="M1.9998,11.2344 L18.0058,20.4744" id="Stroke-25"/>
<path d="M18.0056,20.4746 L1.9996,29.7066" id="Stroke-33"/>
<path d="M34.0036,29.7148 L17.9996,38.9468" id="Stroke-37"/>
<path d="M18.0056,2 L1.9996,29.708" id="Stroke-41"/>
<path d="M3.9998,29.707 C3.9998,30.813 3.1058,31.707 1.9998,31.707 C0.8958,31.707 -0.0002,30.813 -0.0002,29.707 C-0.0002,28.601 0.8958,27.707 1.9998,27.707 C3.1058,27.707 3.9998,28.601 3.9998,29.707 Z" id="Stroke-3" fill="#FFFFFF" fill-rule="nonzero"/>
<path d="M3.9998,11.2344 C3.9998,12.3384 3.1058,13.2344 1.9998,13.2344 C0.8958,13.2344 -0.0002,12.3384 -0.0002,11.2344 C-0.0002,10.1284 0.8958,9.2344 1.9998,9.2344 C3.1058,9.2344 3.9998,10.1284 3.9998,11.2344 Z" id="Stroke-5" fill="#FFFFFF" fill-rule="nonzero"/>
<path d="M19.9998,38.9472 C19.9998,40.0512 19.1058,40.9472 17.9998,40.9472 C16.8958,40.9472 15.9998,40.0512 15.9998,38.9472 C15.9998,37.8412 16.8958,36.9472 17.9998,36.9472 C19.1058,36.9472 19.9998,37.8412 19.9998,38.9472 Z" id="Stroke-7" fill="#FFFFFF" fill-rule="nonzero"/>
<path d="M35.9998,11.2382 C35.9998,12.3442 35.1058,13.2382 33.9998,13.2382 C32.8958,13.2382 31.9998,12.3442 31.9998,11.2382 C31.9998,10.1342 32.8958,9.2382 33.9998,9.2382 C35.1058,9.2382 35.9998,10.1342 35.9998,11.2382 Z" id="Stroke-9" fill="#FFFFFF" fill-rule="nonzero"/>
<path d="M35.9998,29.7148 C35.9998,30.8208 35.1058,31.7148 33.9998,31.7148 C32.8958,31.7148 31.9998,30.8208 31.9998,29.7148 C31.9998,28.6108 32.8958,27.7148 33.9998,27.7148 C35.1058,27.7148 35.9998,28.6108 35.9998,29.7148 Z" id="Stroke-11" fill="#FFFFFF" fill-rule="nonzero"/>
<path d="M20.0056,2 C20.0056,3.106 19.1116,4 18.0056,4 C16.9016,4 16.0056,3.106 16.0056,2 C16.0056,0.896 16.9016,0 18.0056,0 C19.1116,0 20.0056,0.896 20.0056,2 Z" id="Stroke-13" fill="#FFFFFF" fill-rule="nonzero"/>
</g>
</g>
</svg>
@@ -6,14 +6,11 @@

package fetchlib

import cats._
import cats.instances.list._
import cats.syntax.traverse._
import cats.effect._
import cats.implicits._
import fetch._
import fetch.syntax._
import fetch.unsafe.implicits._
import org.scalaexercises.definitions.Section
import org.scalatest.{Assertion, FlatSpec, Matchers}
import org.scalatest.{FlatSpec, Matchers}

/**
* = Batching =
@@ -36,34 +33,36 @@ object BatchingSection extends FlatSpec with Matchers with Section {
* let’s try it out:
*
* {{{
* object BatchedUsers extends Data[UserId, User]{
* def name = "Batched Users"
*
* implicit object BatchedUserSource extends DataSource[UserId, User]{
* override def name = "BatchedUser"
* def source[F[_] : Concurrent]: DataSource[F, UserId, User] = new DataSource[F, UserId, User] {
* override def data = BatchedUsers
*
* override def maxBatchSize: Option[Int] = Some(2)
* override def CF = Concurrent[F]
*
* override def fetchOne(id: UserId): Query[Option[User]] = {
* Query.sync({
* latency(userDatabase.get(id), s"One User $id")
* })
* }
* override def fetchMany(ids: NonEmptyList[UserId]): Query[Map[UserId, User]] = {
* Query.sync({
* latency(userDatabase.filterKeys(ids.toList.contains), s"Many Users $ids")
* })
* }
* }
* override def maxBatchSize: Option[Int] = Some(2)
*
* def getBatchedUser(id: Int): Fetch[User] = Fetch(id)(BatchedUserSource)
* override def fetch(id: UserId): F[Option[User]] =
* latency[F](s"One User $id") >> CF.pure(userDatabase.get(id))
*
* override def batch(ids: NonEmptyList[UserId]): F[Map[UserId, User]] =
* latency[F](s"Batch Users $ids") >> CF.pure(userDatabase.filterKeys(ids.toList.toSet).toMap)
* }
* }
*
* def getBatchedUser[F[_] : Concurrent](id: Int): Fetch[F, User] =
* Fetch(id, BatchedUsers.source)
* }}}
*
* We have defined the maximum batch size to be 2,
* let’s see what happens when running a fetch that needs more than two users:
*/
def maximumSize(res0: Int) = {
val fetchManyBatchedUsers: Fetch[List[User]] = List(1, 2, 3, 4).traverse(getBatchedUser)
fetchManyBatchedUsers.runE[Id].rounds.size shouldBe res0
def fetchManyBatchedUsers[F[_]: Concurrent]: Fetch[F, List[User]] =
List(1, 2, 3, 4).traverse(getBatchedUser[F])

Fetch.run[IO](fetchManyBatchedUsers).unsafeRunSync().size shouldBe res0
}

/**
@@ -74,36 +73,37 @@ object BatchingSection extends FlatSpec with Matchers with Section {
* but you can tweak it by overriding `DataSource#batchExection`.
*
* {{{
* object SequentialUsers extends Data[UserId, User]{
* def name = "Sequential Users"
*
* implicit object SequentialUserSource extends DataSource[UserId, User]{
* override def name = "SequentialUser"
* def source[F[_] : Concurrent]: DataSource[F, UserId, User] = new DataSource[F, UserId, User] {
* override def data = SequentialUsers
*
* override def maxBatchSize: Option[Int] = Some(2)
* override def CF = Concurrent[F]
*
* override def batchExecution: ExecutionType = Sequential
* override def maxBatchSize: Option[Int] = Some(2)
* override def batchExecution: BatchExecution = Sequentially // defaults to `InParallel`
*
* override def fetchOne(id: UserId): Query[Option[User]] = {
* Query.sync({
* latency(userDatabase.get(id), s"One User $id")
* })
* }
* override def fetchMany(ids: NonEmptyList[UserId]): Query[Map[UserId, User]] = {
* Query.sync({
* latency(userDatabase.filterKeys(ids.toList.contains), s"Many Users $ids")
* })
* }
* }
* override def fetch(id: UserId): F[Option[User]] =
* latency[F](s"One User $id") >> CF.pure(userDatabase.get(id))
*
* def getSequentialUser(id: Int): Fetch[User] = Fetch(id)(SequentialUserSource)
* override def batch(ids: NonEmptyList[UserId]): F[Map[UserId, User]] =
* latency[F](s"Batch Users $ids") >> CF.pure(userDatabase.filterKeys(ids.toList.toSet).toMap)
* }
* }
*
* def getSequentialUser[F[_] : Concurrent](id: Int): Fetch[F, User] =
* Fetch(id, SequentialUsers.source)
* }}}
*
* We have defined the maximum batch size to be 2 and the batch execution to be sequential,
* let’s see what happens when running a fetch that needs more than one batch:
*
*/
def executionStrategy(res0: Int) = {
val fetchManySeqBatchedUsers: Fetch[List[User]] = List(1, 2, 3, 4).traverse(getSequentialUser)
fetchManySeqBatchedUsers.runE[Id].rounds.size shouldBe res0
def fetchManySeqBatchedUsers[F[_]: Concurrent]: Fetch[F, List[User]] =
List(1, 2, 3, 4).traverse(getSequentialUser[F])

Fetch.run[IO](fetchManySeqBatchedUsers).unsafeRunSync().size shouldBe res0
}
}
@@ -6,10 +6,8 @@

package fetchlib

import cats._
import cats.effect.{Concurrent, IO}
import cats.instances.list._
import cats.syntax.traverse._
import cats.implicits._
import fetch._
import org.scalaexercises.definitions.Section
import org.scalatest.{FlatSpec, Matchers}
@@ -123,14 +121,14 @@ object CachingSection extends FlatSpec with Matchers with Section {
*
* We can now use our implementation of the cache when running a fetch.
*/
def customCache(res0: Int) = {
def customCache(res0: User) = {
def fetchSameTwice[F[_]: Concurrent]: Fetch[F, (User, User)] =
for {
one <- getUser(1)
another <- getUser(1)
} yield (one, another)

Fetch.run[IO](fetchSameTwice, forgetfulCache).unsafeRunSync() shouldBe res0
Fetch.run[IO](fetchSameTwice, forgetfulCache).unsafeRunSync()._1 shouldBe res0
}

}

0 comments on commit 40d5ecc

Please sign in to comment.
You can’t perform that action at this time.