This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vitaliihonta
committed
Feb 1, 2019
1 parent
0622edf
commit 3fb4dcf
Showing
17 changed files
with
208 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
kernel/src/main/scala/trembita/operations/CanBatched.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package trembita.operations | ||
|
||
import trembita.internal.BatchUtils | ||
import scala.collection.parallel.immutable.ParVector | ||
import scala.language.higherKinds | ||
|
||
trait CanBatched[F[_]] { | ||
def batched[A](fa: F[A], parts: Int): F[Iterable[A]] | ||
} | ||
|
||
object CanBatched { | ||
implicit val vectorCanBeBatched: CanBatched[Vector] = new CanBatched[Vector] { | ||
def batched[A](fa: Vector[A], parts: Int): Vector[Iterable[A]] = BatchUtils.batch(parts)(fa).toVector | ||
} | ||
implicit val parVectorCanBeCatched: CanBatched[ParVector] = new CanBatched[ParVector] { | ||
def batched[A](fa: ParVector[A], parts: Int): ParVector[Iterable[A]] = BatchUtils.batch(parts)(fa.seq).toVector.par | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package trembita.operations | ||
|
||
import cats.Monad | ||
import cats.syntax.all._ | ||
import scala.collection.parallel.immutable.ParVector | ||
import scala.language.higherKinds | ||
|
||
trait CanFoldF[F[_], G[_]] { | ||
def foldF[A, B](fa: F[A])(zero: B)(f: (B, A) => G[B]): G[B] | ||
} | ||
|
||
object CanFoldF { | ||
implicit def canFoldFVector[F[_]: Monad]: CanFoldF[Vector, F] = new CanFoldF[Vector, F] { | ||
def foldF[A, B](fa: Vector[A])(zero: B)(f: (B, A) => F[B]): F[B] = | ||
fa.foldLeft(zero.pure[F])( | ||
(gb, a) => | ||
gb.flatMap { b => | ||
f(b, a) | ||
} | ||
) | ||
} | ||
|
||
implicit def canFoldFParVector[F[_]: Monad]: CanFoldF[ParVector, F] = new CanFoldF[ParVector, F] { | ||
def foldF[A, B](fa: ParVector[A])(zero: B)(f: (B, A) => F[B]): F[B] = | ||
fa.foldLeft(zero.pure[F])( | ||
(gb, a) => | ||
gb.flatMap { b => | ||
f(b, a) | ||
} | ||
) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
kernel/src/main/scala/trembita/operations/CanGrouped.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package trembita.operations | ||
import scala.collection.parallel.immutable.ParVector | ||
import scala.language.higherKinds | ||
|
||
trait CanGrouped[F[_]] { | ||
def grouped[A](fa: F[A], n: Int): F[Iterable[A]] | ||
} | ||
|
||
object CanGrouped { | ||
implicit val vectorCanBeGrouped: CanGrouped[Vector] = new CanGrouped[Vector] { | ||
def grouped[A](fa: Vector[A], n: Int): Vector[Iterable[A]] = fa.grouped(n).toVector | ||
} | ||
implicit val parVectorCanBeGrouped: CanGrouped[ParVector] = new CanGrouped[ParVector] { | ||
def grouped[A](fa: ParVector[A], n: Int): ParVector[Iterable[A]] = fa.seq.grouped(n).toVector.par | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.