-
Notifications
You must be signed in to change notification settings - Fork 53
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 #78 from LMnet/mapat
Relax type constraint for QuicklensMapAt
- Loading branch information
Showing
3 changed files
with
72 additions
and
24 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
28 changes: 28 additions & 0 deletions
28
quicklens/src/test/scala-2/com.softwaremill.quicklens/QuicklensMapAtFunctorTest.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,28 @@ | ||
package com.softwaremill.quicklens | ||
|
||
import com.softwaremill.quicklens.TestData._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class QuicklensMapAtFunctorTest extends AnyFlatSpec with Matchers { | ||
|
||
"QuicklensMapAtFunctor" should "work for types which is not a subtype of Map" in { | ||
case class MapLike[K, V](underlying: Map[K, V]) | ||
|
||
implicit def instance[K, T]: QuicklensMapAtFunctor[MapLike, K, T] = new QuicklensMapAtFunctor[MapLike, K, T] { | ||
private val mapInstance: QuicklensMapAtFunctor[Map, K, T] = | ||
implicitly[QuicklensMapAtFunctor[Map, K, T]] | ||
|
||
def at(fa: MapLike[K, T], idx: K)(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.at(fa.underlying, idx)(f)) | ||
def atOrElse(fa: MapLike[K, T], idx: K, default: => T)(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.atOrElse(fa.underlying, idx, default)(f)) | ||
def index(fa: MapLike[K, T], idx: K)(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.index(fa.underlying, idx)(f)) | ||
def each(fa: MapLike[K, T])(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.each(fa.underlying)(f)) | ||
} | ||
|
||
modify(MapLike(m1))(_.at("K1").a5.name).using(duplicate) should be(MapLike(m1dup)) | ||
} | ||
} |