-
Notifications
You must be signed in to change notification settings - Fork 0
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 #90 from Kevin-Lee/task/89/add-writer-syntax
Close #89 - Add writer syntax
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package just.fp.syntax | ||
|
||
import just.fp.Writer | ||
|
||
import scala.language.implicitConversions | ||
|
||
/** | ||
* @author Kevin Lee | ||
* @since 2019-10-02 | ||
*/ | ||
object WriterOps { | ||
final class ToWriter[A](val a: A) extends AnyVal { | ||
def writer[W](w: W): Writer[W, A] = Writer(w, a) | ||
} | ||
} | ||
|
||
trait WriterSyntax { | ||
import WriterOps._ | ||
|
||
@SuppressWarnings(Array("org.wartremover.warts.ImplicitConversion")) | ||
implicit final def toWriter[A](a: A): ToWriter[A] = new ToWriter(a) | ||
} |
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ package object syntax | |
with OptionSyntax | ||
with EitherSyntax | ||
with SemiGroupSyntax | ||
with WriterSyntax |
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,28 @@ | ||
package just.fp.syntax | ||
|
||
import hedgehog._ | ||
import hedgehog.runner._ | ||
|
||
import just.fp.Gens | ||
|
||
/** | ||
* @author Kevin Lee | ||
* @since 2019-10-02 | ||
*/ | ||
object WriterSyntaxSpec extends Properties { | ||
override def tests: List[Test] = List( | ||
property("test value.writer(w) syntax", testValueWriter) | ||
) | ||
|
||
def testValueWriter: Property = for { | ||
a <- Gens.genIntFromMinToMax.log("a") | ||
w <- Gens.genUnicodeString.log("w") | ||
} yield { | ||
import just.fp._ | ||
|
||
val expected = Writer(w, a) | ||
val actual = a.writer(w) | ||
|
||
actual ==== expected | ||
} | ||
} |