Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#57] Add a libra module
Fixes #57.
- Loading branch information
Showing
6 changed files
with
139 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
layout: tutorial | ||
title: "Libra module" | ||
section: tutorial | ||
sort_order: 15 | ||
--- | ||
kantan.regex comes with a [libra](https://github.com/to-ithaca/libra) module that can be used | ||
by adding the following dependency to your `build.sbt`: | ||
|
||
```scala | ||
libraryDependencies += "com.nrinaudo" %% "kantan.regex-libra" % "@VERSION@" | ||
``` | ||
|
||
You then need to import the corresponding package: | ||
|
||
```tut:silent | ||
import kantan.regex.libra._ | ||
``` | ||
|
||
And that's pretty much it. You can now decode refined types directly. | ||
|
||
Let's first set our types up: | ||
|
||
```tut:silent | ||
import libra._ | ||
import libra.si._ | ||
import kantan.regex.implicits._ | ||
type Duration = QuantityOf[Int, Time, Second] | ||
``` | ||
|
||
We can then simply write the following: | ||
|
||
```tut | ||
"[123]".evalRegex[Duration](rx"\[([+-]?\d+)\]", 1).toList | ||
``` |
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 @@ | ||
/* | ||
* Copyright 2016 Nicolas Rinaudo | ||
* | ||
* 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 kantan.regex | ||
|
||
import kantan.codecs.libra.DecoderInstances | ||
|
||
package object libra extends DecoderInstances |
39 changes: 39 additions & 0 deletions
39
libra/src/test/scala/kantan/regex/libra/LibraCodecTests.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,39 @@ | ||
/* | ||
* Copyright 2016 Nicolas Rinaudo | ||
* | ||
* 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 kantan.regex | ||
package libra | ||
|
||
import _root_.libra.Quantity | ||
import arbitrary._ | ||
import laws.discipline._ | ||
import shapeless.HNil | ||
|
||
class LibraCodecTests extends DisciplineSuite { | ||
|
||
checkAll("GroupDecoder[Quantity[Double, HNil]]", GroupDecoderTests[Quantity[Double, HNil]].decoder[String, Float]) | ||
checkAll("GroupDecoder[Quantity[Double, HNil]]", SerializableTests[GroupDecoder[Quantity[Double, HNil]]].serializable) | ||
|
||
checkAll("MatchDecoder[Quantity[Double, HNil]]", MatchDecoderTests[Quantity[Double, HNil]].decoder[String, Float]) | ||
checkAll("MatchDecoder[Quantity[Double, HNil]]", SerializableTests[MatchDecoder[Quantity[Double, HNil]]].serializable) | ||
|
||
checkAll("GroupDecoder[Quantity[Int, HNil]]", GroupDecoderTests[Quantity[Int, HNil]].decoder[String, Float]) | ||
checkAll("GroupDecoder[Quantity[Int, HNil]]", SerializableTests[GroupDecoder[Quantity[Int, HNil]]].serializable) | ||
|
||
checkAll("MatchDecoder[Quantity[Int, HNil]]", MatchDecoderTests[Quantity[Int, HNil]].decoder[String, Float]) | ||
checkAll("MatchDecoder[Quantity[Int, HNil]]", SerializableTests[MatchDecoder[Quantity[Int, HNil]]].serializable) | ||
|
||
} |
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 @@ | ||
/* | ||
* Copyright 2016 Nicolas Rinaudo | ||
* | ||
* 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 kantan.regex | ||
package libra | ||
|
||
object arbitrary | ||
extends kantan.regex.laws.discipline.ArbitraryInstances with kantan.codecs.libra.laws.discipline.ArbitraryInstances |