Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add new parsers and shows for AWS providers - change parsers to functors and provide instances - provide contravariant instances for shows - add tests for new instances
- Loading branch information
1 parent
7b289fd
commit 26f3c83
Showing
20 changed files
with
312 additions
and
69 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 |
---|---|---|
@@ -1,13 +1,24 @@ | ||
package extruder.aws | ||
|
||
import com.amazonaws.regions.{Region, Regions} | ||
import com.amazonaws.regions.{AwsRegionProvider, Region, Regions} | ||
import extruder.core.{Parser, Show} | ||
|
||
trait AwsRegionInstances { | ||
implicit def awsRegionParser: Parser[Region] = | ||
implicit val awsRegionParser: Parser[Region] = | ||
Parser.catchNonFatal(region => Region.getRegion(Regions.fromName(region))) | ||
|
||
implicit def awsRegionShow: Show[Region] = Show { r: Region => | ||
implicit val awsRegionProviderParser: Parser[AwsRegionProvider] = awsRegionParser.map( | ||
region => | ||
new AwsRegionProvider { | ||
override def getRegion: String = region.getName | ||
} | ||
) | ||
|
||
implicit val awsRegionShow: Show[Region] = Show { r: Region => | ||
r.getName | ||
} | ||
|
||
implicit val awsRegionProviderShow: Show[AwsRegionProvider] = Show { rp: AwsRegionProvider => | ||
rp.getRegion | ||
} | ||
} |
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
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
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,3 @@ | ||
package extruder.instances | ||
|
||
trait AllInstances extends MultiParserInstances with MultiShowInstances with ParserInstances with ShowInstances |
11 changes: 11 additions & 0 deletions
11
core/src/main/scala/extruder/instances/MultiParserInstances.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,11 @@ | ||
package extruder.instances | ||
|
||
import cats.Functor | ||
import extruder.core.MultiParser | ||
|
||
trait MultiParserInstances { | ||
implicit def extruderStdInstancesForMultiParser[F[_]: Functor]: Functor[MultiParser[F, ?]] = | ||
new Functor[MultiParser[F, ?]] { | ||
override def map[A, B](fa: MultiParser[F, A])(f: A => B): MultiParser[F, B] = fa.map(f) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core/src/main/scala/extruder/instances/MultiShowInstances.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,12 @@ | ||
package extruder.instances | ||
|
||
import cats.Contravariant | ||
import extruder.core.MultiShow | ||
|
||
trait MultiShowInstances { | ||
implicit val extruderStdInstancesForMultiShow: Contravariant[MultiShow] = new Contravariant[MultiShow] { | ||
override def contramap[A, B](fa: MultiShow[A])(f: B => A): MultiShow[B] = new MultiShow[B] { | ||
override def show(b: B): Map[List[String], String] = fa.show(f(b)) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/scala/extruder/instances/ParserInstances.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,10 @@ | ||
package extruder.instances | ||
|
||
import cats.Functor | ||
import extruder.core.Parser | ||
|
||
trait ParserInstances { | ||
implicit val extruderStdInstancesForParser: Functor[Parser] = new Functor[Parser] { | ||
override def map[A, B](fa: Parser[A])(f: A => B): Parser[B] = fa.map(f) | ||
} | ||
} |
Oops, something went wrong.