-
Notifications
You must be signed in to change notification settings - Fork 22
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
Showing
5 changed files
with
104 additions
and
23 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,21 @@ | ||
package iota //#=cats | ||
package iotaz //#=scalaz | ||
package syntax | ||
|
||
final class InjectOps[A](val a: A) extends AnyVal { | ||
def inject[B <: Cop[_]](implicit ev: Cop.Inject[A, B]): B = | ||
ev.inj(a) | ||
} | ||
|
||
trait InjectSyntax { | ||
implicit def toInjectOps[A](a: A): InjectOps[A] = new InjectOps(a) | ||
} | ||
|
||
final class InjectKOps[F[_], A](val fa: F[A]) extends AnyVal { | ||
def injectK[G[_] <: CopK[_, _]](implicit ev: CopK.Inject[F, G]): G[A] = | ||
ev.inj(fa) | ||
} | ||
|
||
trait InjectKSyntax { | ||
implicit def toInjectKOps[F[_], A](fa: F[A]): InjectKOps[F, A] = new InjectKOps(fa) | ||
} |
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,11 @@ | ||
package iota //#=cats | ||
package iotaz //#=scalaz | ||
|
||
package object syntax { | ||
object inject extends InjectSyntax | ||
object injectK extends InjectKSyntax | ||
|
||
object all | ||
extends InjectSyntax | ||
with InjectKSyntax | ||
} |
47 changes: 47 additions & 0 deletions
47
modules/examples/src/main/scala/iotaexamples/InjectSyntax.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,47 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package iotaexamples | ||
|
||
import iota._ | ||
import iota.syntax.all._ | ||
|
||
import scala.Predef._ | ||
|
||
object InjectSyntax extends App { | ||
import TList.:: | ||
import TListK.::: | ||
|
||
object Luna | ||
object Mabel | ||
object Finn | ||
object Cinder | ||
object Bridger | ||
|
||
type Dog = Cop[ | ||
Luna.type :: Mabel.type :: Finn.type :: Cinder.type :: Bridger.type :: TNil] | ||
|
||
val dog0: Dog = Luna.inject[Dog] | ||
val dog1: Dog = Finn.inject[Dog] | ||
|
||
println(dog0) | ||
println(dog1) | ||
|
||
type Wat[A] = CopK[List ::: Option ::: TNilK, A] | ||
|
||
val res0: Wat[String] = List("hello", "world").injectK[Wat] | ||
val res1: Wat[Int] = Option(1).injectK[Wat] | ||
} |
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