Skip to content

Commit

Permalink
Adding contramap to VendorExtensible
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Oct 3, 2019
1 parent eaca759 commit df5d50c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Expand Up @@ -9,6 +9,12 @@ import io.swagger.v3.oas.models.security.SecurityScheme
object VendorExtension {
trait VendorExtensible[-F] {
def extract[T](from: F, key: String)(implicit T: Extractable[T]): Option[T]
def contramap[B](f: B => F): VendorExtensible[B] = {
val chain = this
new VendorExtensible[B] {
def extract[T](from: B, key: String)(implicit T: Extractable[T]): Option[T] = chain.extract(f(from), key)
}
}
}

object VendorExtensible {
Expand Down
Expand Up @@ -16,11 +16,11 @@ package syntax {
(" " * indent) + value.toString().linesIterator.filterNot(_.contains(": null")).mkString("\n" + (" " * indent))
}

class RichCollection[A, Repr](xs: IterableLike[A, Repr]) {
class RichCollection[A, Repr](xs: IterableLike[A, Repr]){
def distinctBy[B, That](f: A => B)(implicit cbf: CanBuildFrom[Repr, A, That]) = {
val builder = cbf(xs.repr)
val i = xs.iterator
var set = Set[B]()
val i = xs.iterator
var set = Set[B]()
while (i.hasNext) {
val o = i.next
val b = f(o)
Expand Down Expand Up @@ -88,9 +88,9 @@ package object syntax {
def toDashedCase: String = splitParts(s).mkString("-")
}

implicit def RichSchema = new RichNotNullShower[Schema[_]](_)
implicit def RichSchema = new RichNotNullShower[Schema[_]](_)
implicit def RichOperation = new RichNotNullShower[Operation](_)
implicit def RichPathItem = new RichNotNullShower[PathItem](_)
implicit def RichPathItem = new RichNotNullShower[PathItem](_)
implicit def RichParameter = new RichNotNullShower[Parameter](_)

implicit def toRichCollection[A, Repr](xs: IterableLike[A, Repr]) = new RichCollection(xs)
Expand Down

0 comments on commit df5d50c

Please sign in to comment.