-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from milessabin/master
Initial support for export-hook
- Loading branch information
Showing
13 changed files
with
133 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package alleycats | ||
|
||
import cats.SemigroupK | ||
import export.imports | ||
import simulacrum.typeclass | ||
|
||
@typeclass trait ConsK[F[_]] { | ||
def cons[A](hd: A, tl: F[A]): F[A] | ||
} | ||
|
||
object ConsK extends ConsK0 { | ||
implicit def pureSemigroupKIsConsK[F[_]](implicit p: Pure[F], s: SemigroupK[F]): ConsK[F] = | ||
new ConsK[F] { | ||
def cons[A](hd: A, tl: F[A]): F[A] = s.combine(p.pure(hd), tl) | ||
} | ||
} | ||
|
||
@imports[ConsK] | ||
trait ConsK0 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
package alleycats | ||
|
||
import cats.{Applicative, CoflatMap, Comonad} | ||
import export.imports | ||
import simulacrum.typeclass | ||
|
||
@typeclass trait Extract[F[_]] { | ||
def extract[A](fa: F[A]): A | ||
} | ||
|
||
object Extract { | ||
object Extract extends Extract0 { | ||
// Ideally this would be an exported subclass instance provided by Comonad | ||
implicit def comonadIsExtract[F[_]](implicit ev: Comonad[F]): Extract[F] = | ||
new Extract[F] { | ||
def extract[A](fa: F[A]): A = ev.extract(fa) | ||
} | ||
|
||
// Ideally this would be an instance exported to Comonad | ||
implicit def extractCoflatMapIsComonad[F[_]](implicit e: Extract[F], cf: CoflatMap[F]): Comonad[F] = | ||
new Comonad[F] { | ||
def extract[A](fa: F[A]): A = e.extract(fa) | ||
override def map[A, B](fa: F[A])(f: A => B): F[B] = cf.map(fa)(f) | ||
def coflatMap[A, B](fa: F[A])(f: F[A] => B): F[B] = cf.coflatMap(fa)(f) | ||
} | ||
} | ||
|
||
@imports[Extract] | ||
trait Extract0 |
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 |
---|---|---|
@@ -1,22 +1,28 @@ | ||
package alleycats | ||
|
||
import cats.{Applicative, FlatMap, Monad} | ||
import export.imports | ||
import simulacrum.typeclass | ||
|
||
@typeclass trait Pure[F[_]] { | ||
def pure[A](a: A): F[A] | ||
} | ||
|
||
object Pure { | ||
object Pure extends Pure0 { | ||
// Ideally this would be an exported subclass instance provided by Applicative | ||
implicit def applicativeIsPure[F[_]](implicit ev: Applicative[F]): Pure[F] = | ||
new Pure[F] { | ||
def pure[A](a: A): F[A] = ev.pure(a) | ||
} | ||
|
||
// Ideally this would be an instance exported to Monad | ||
implicit def pureFlatMapIsMonad[F[_]](implicit p: Pure[F], fm: FlatMap[F]): Monad[F] = | ||
new Monad[F] { | ||
def pure[A](a: A): F[A] = p.pure(a) | ||
override def map[A, B](fa: F[A])(f: A => B): F[B] = fm.map(fa)(f) | ||
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] = fm.flatMap(fa)(f) | ||
} | ||
} | ||
|
||
@imports[Pure] | ||
trait Pure0 |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package alleycats.std | ||
package alleycats | ||
package std | ||
|
||
object all | ||
extends ListInstances | ||
with OptionInstances | ||
with SetInstances | ||
with TryInstances | ||
import export._ | ||
|
||
@reexports( | ||
EmptyKInstances, | ||
ListInstances, | ||
OptionInstances, | ||
SetInstances, | ||
TryInstances | ||
) object all extends LegacySetInstances with LegacyTryInstances |
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 |
---|---|---|
@@ -1,11 +1,22 @@ | ||
package alleycats | ||
package std | ||
|
||
object list extends ListInstances | ||
import export._ | ||
|
||
trait ListInstances { | ||
implicit val listEmptyK: EmptyK[List] = | ||
@reexports(ListInstances) | ||
object list | ||
|
||
@exports | ||
object ListInstances { | ||
@export(Orphan) | ||
implicit val exportListEmptyK: EmptyK[List] = | ||
new EmptyK[List] { | ||
def empty[A]: List[A] = Nil | ||
} | ||
|
||
@export(Orphan) | ||
implicit val exportListConsK: ConsK[List] = | ||
new ConsK[List] { | ||
def cons[A](hd: A, tl: List[A]): List[A] = hd :: tl | ||
} | ||
} |
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