Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Remove Deprecated Id<A> data type (#94)
Browse files Browse the repository at this point in the history
* Remove Id typeclass references

* Remove Id tests
  • Loading branch information
danimontoya committed Jan 25, 2021
1 parent ca1eac0 commit 9d7073b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package arrow.optics.test.laws

import arrow.core.Const
import arrow.core.Id
import arrow.core.compose
import arrow.core.extensions.const.applicative.applicative
import arrow.core.extensions.id.functor.functor
import arrow.core.identity
import arrow.core.value
import arrow.optics.Iso
Expand All @@ -24,7 +22,6 @@ object IsoLaws {
Law("Iso Law: modify identity is identity") { iso.modifyIdentity(aGen, EQA) },
Law("Iso Law: compose modify") { iso.composeModify(aGen, funcGen, EQA) },
Law("Iso Law: consitent set with modify") { iso.consistentSetModify(aGen, bGen, EQA) },
Law("Iso Law: consistent modify with modify identity") { iso.consistentModifyModifyId(aGen, funcGen, EQA) },
Law("Iso Law: consitent get with modify identity") { iso.consitentGetModifyId(aGen, EQB, bMonoid) }
)

Expand Down Expand Up @@ -53,11 +50,6 @@ object IsoLaws {
set(b).equalUnderTheLaw(modify(a) { b }, EQA)
}

fun <A, B> Iso<A, B>.consistentModifyModifyId(aGen: Gen<A>, funcGen: Gen<(B) -> B>, EQA: Eq<A>): Unit =
forAll(aGen, funcGen) { a, f ->
modify(a, f).equalUnderTheLaw(modifyF(Id.functor(), a) { Id.just(f(it)) }.value(), EQA)
}

fun <A, B> Iso<A, B>.consitentGetModifyId(aGen: Gen<A>, EQB: Eq<B>, bMonoid: Monoid<B>): Unit =
forAll(aGen) { a ->
get(a).equalUnderTheLaw(modifyF(Const.applicative(bMonoid), a, ::Const).value(), EQB)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package arrow.optics.test.laws

import arrow.core.Const
import arrow.core.Id
import arrow.core.compose
import arrow.core.extensions.const.applicative.applicative
import arrow.core.extensions.id.functor.functor
import arrow.core.identity
import arrow.core.value
import arrow.optics.Lens
Expand Down Expand Up @@ -33,7 +31,6 @@ object LensLaws {
Law("Lens law: modify identity") { lensModifyIdentity(lensGen, aGen, EQA) },
Law("Lens law: compose modify") { lensComposeModify(lensGen, aGen, funcGen, EQA) },
Law("Lens law: consistent set modify") { lensConsistentSetModify(lensGen, aGen, bGen, EQA) },
Law("Lens law: consistent modify modify id") { lensConsistentModifyModifyId(lensGen, aGen, funcGen, EQA) },
Law("Lens law: consistent get modify id") { lensConsistentGetModifyid(lensGen, aGen, EQB, MB) }
)

Expand Down Expand Up @@ -92,14 +89,6 @@ object LensLaws {
}
}

fun <A, B> lensConsistentModifyModifyId(lensGen: Gen<Lens<A, B>>, aGen: Gen<A>, funcGen: Gen<(B) -> B>, EQA: Eq<A>) =
forAll(lensGen, aGen, funcGen) { lens, a, f ->
lens.run {
modify(a, f)
.equalUnderTheLaw(modifyF(Id.functor(), a) { Id.just(f(it)) }.value(), EQA)
}
}

fun <A, B> lensConsistentGetModifyid(lensGen: Gen<Lens<A, B>>, aGen: Gen<A>, EQB: Eq<B>, MA: Monoid<B>) =
forAll(lensGen, aGen) { lens, a ->
lens.run {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package arrow.optics.test.laws

import arrow.core.Const
import arrow.core.Id
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.compose
import arrow.core.extensions.const.applicative.applicative
import arrow.core.extensions.id.applicative.applicative
import arrow.core.identity
import arrow.core.value
import arrow.optics.Optional
Expand All @@ -34,14 +32,6 @@ object OptionalLaws {
Law("Optional Law: modify identity = identity") { modifyIdentity(optionalGen, aGen, EQA) },
Law("Optional Law: compose modify") { composeModify(optionalGen, aGen, funcGen, EQA) },
Law("Optional Law: consistent set with modify") { consistentSetModify(optionalGen, aGen, bGen, EQA) },
Law("Optional Law: consistent modify with modify identity") {
consistentModifyModifyId(
optionalGen,
aGen,
funcGen,
EQA
)
},
Law("Optional Law: consistent getOption with modify identity") {
consistentGetOptionModifyId(
optionalGen,
Expand Down Expand Up @@ -116,19 +106,6 @@ object OptionalLaws {
}
}

fun <A, B> consistentModifyModifyId(
optionalGen: Gen<Optional<A, B>>,
aGen: Gen<A>,
funcGen: Gen<(B) -> B>,
EQA: Eq<A>
): Unit =
forAll(optionalGen, aGen, funcGen) { optional, a, f ->
optional.run {
modify(a, f)
.equalUnderTheLaw(modifyF(Id.applicative(), a) { Id.just(f(it)) }.value(), EQA)
}
}

fun <A, B> consistentGetOptionModifyId(
optionalGen: Gen<Optional<A, B>>,
aGen: Gen<A>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package arrow.optics.test.laws

import arrow.core.Const
import arrow.core.Id
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.compose
import arrow.core.extensions.const.applicative.applicative
import arrow.core.extensions.id.applicative.applicative
import arrow.core.identity
import arrow.core.orElse
import arrow.core.value
Expand All @@ -27,7 +25,6 @@ object PrismLaws {
Law("Prism law: modify identity") { prism.modifyIdentity(aGen, EQA) },
Law("Prism law: compose modify") { prism.composeModify(aGen, funcGen, EQA) },
Law("Prism law: consistent set modify") { prism.consistentSetModify(aGen, bGen, EQA) },
Law("Prism law: consistent modify with modifyF Id") { prism.consistentModifyModifyFId(aGen, funcGen, EQA) },
Law("Prism law: consistent get option modify id") { prism.consistentGetOptionModifyId(aGen, EQOptionB) }
)

Expand Down Expand Up @@ -58,11 +55,6 @@ object PrismLaws {
set(a, b).equalUnderTheLaw(modify(a) { b }, EQA)
}

fun <A, B> Prism<A, B>.consistentModifyModifyFId(aGen: Gen<A>, funcGen: Gen<(B) -> B>, EQA: Eq<A>): Unit =
forAll(aGen, funcGen) { a, f ->
modifyF(Id.applicative(), a) { Id.just(f(it)) }.value().equalUnderTheLaw(modify(a, f), EQA)
}

fun <A, B> Prism<A, B>.consistentGetOptionModifyId(aGen: Gen<A>, EQOptionB: Eq<Option<B>>): Unit =
forAll(aGen) { a ->
modifyF(Const.applicative(object : Monoid<Option<B>> {
Expand Down
7 changes: 4 additions & 3 deletions arrow-optics/src/main/kotlin/arrow/optics/Traversal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package arrow.optics
import arrow.Kind
import arrow.core.Const
import arrow.core.Either
import arrow.core.Id
import arrow.core.ListK
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.extensions.AndMonoid
import arrow.core.extensions.const.applicative.applicative
import arrow.core.extensions.id.applicative.applicative
import arrow.core.extensions.listk.monoid.monoid
import arrow.core.extensions.monoid
import arrow.core.identity
import arrow.core.value
import arrow.optics.typeclasses.Id
import arrow.optics.typeclasses.fix
import arrow.optics.typeclasses.idApplicative
import arrow.typeclasses.Applicative
import arrow.typeclasses.Monoid
import arrow.typeclasses.Traverse
Expand Down Expand Up @@ -354,7 +355,7 @@ interface PTraversal<S, T, A, B> : PTraversalOf<S, T, A, B> {
/**
* Modify polymorphically the target of a [PTraversal] with a function [f]
*/
fun modify(s: S, f: (A) -> B): T = modifyF(Id.applicative(), s) { b -> Id(f(b)) }.value()
fun modify(s: S, f: (A) -> B): T = modifyF(idApplicative, s) { b -> Id(f(b)) }.fix().value

/**
* Check whether at least one element satisfies the predicate.
Expand Down
7 changes: 3 additions & 4 deletions arrow-optics/src/main/kotlin/arrow/optics/std/id.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package arrow.optics

import arrow.core.Id
import arrow.core.value
import arrow.optics.typeclasses.Id

/**
* [PIso] that defines the equality between a [Id] wrapped type [A] and the type [A] itself.
*/
fun <A, B> Id.Companion.toPValue(): PIso<Id<A>, Id<B>, A, B> = PIso(
internal fun <A, B> Id.Companion.toPValue(): PIso<Id<A>, Id<B>, A, B> = PIso(
get = Id<A>::value,
reverseGet = ::Id
)

/**
* [Iso] that defines the equality between a [Id] wrapped type [A] and the type [A] itself.
*/
fun <A> Id.Companion.toValue(): Iso<Id<A>, A> = toPValue()
internal fun <A> Id.Companion.toValue(): Iso<Id<A>, A> = toPValue()
16 changes: 16 additions & 0 deletions arrow-optics/src/main/kotlin/arrow/optics/typeclasses/internal.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package arrow.optics.typeclasses

import arrow.Kind
import arrow.typeclasses.Applicative

internal data class Id<out A>(val value: A) : Kind<Id.Companion, A> {
internal companion object
}

internal fun <A> Kind<Id.Companion, A>.fix(): Id<A> = this as Id<A>

internal object idApplicative : Applicative<Id.Companion> {
override fun <A> just(a: A): Kind<Id.Companion, A> = Id(a)
override fun <A, B> Kind<Id.Companion, A>.ap(ff: Kind<Id.Companion, (A) -> B>): Kind<Id.Companion, B> =
Id(ff.fix().value(fix().value))
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package arrow.optics.std

import arrow.core.Id
import arrow.core.extensions.monoid
import arrow.optics.toValue
import arrow.core.test.UnitSpec
import arrow.core.test.generators.functionAToB
import arrow.optics.test.laws.IsoLaws
import arrow.optics.toValue
import arrow.optics.typeclasses.Id
import arrow.typeclasses.Eq
import io.kotlintest.properties.Gen

Expand Down

0 comments on commit 9d7073b

Please sign in to comment.