-
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.
Updated to latest build; added right to left demo.
Miles Sabin
committed
Apr 18, 2016
1 parent
f0283f2
commit ca31b36
Showing
2 changed files
with
30 additions
and
1 deletion.
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,29 @@ | ||
package si2712fix | ||
|
||
import scala.annotation.unifyRightToLeft | ||
|
||
// Cats Xor, Scalaz \/, scala.util.Either | ||
sealed abstract class Xor[+A, +B] extends Product with Serializable | ||
object Xor { | ||
final case class Left[+A](a: A) extends (A Xor Nothing) | ||
final case class Right[+B](b: B) extends (Nothing Xor B) | ||
} | ||
|
||
object TestXor { | ||
import Xor._ | ||
def meh[F[_], A, B](fa: F[A])(f: A => B): F[B] = ??? | ||
meh(new Right(23): Xor[Boolean, Int])(_ < 13) | ||
meh(new Left(true): Xor[Boolean, Int])(_ < 13) | ||
} | ||
|
||
// Scalactic Or | ||
@unifyRightToLeft | ||
sealed abstract class Or[+G,+B] | ||
final case class Good[+G](g: G) extends Or[G,Nothing] | ||
final case class Bad[+B](b: B) extends Or[Nothing,B] | ||
|
||
object TestOr { | ||
def meh[F[_], A, B](fa: F[A])(f: A => B): F[B] = ??? | ||
meh(new Good(23): Or[Int, Boolean])(_ < 13) | ||
meh(new Bad(true): Or[Int, Boolean])(_ < 13) | ||
} |