Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optics module with initial lens impl #251

Merged
merged 4 commits into from
Sep 5, 2017
Merged

Optics module with initial lens impl #251

merged 4 commits into from
Sep 5, 2017

Conversation

nomisRev
Copy link
Member

@nomisRev nomisRev commented Sep 4, 2017

I was unsure about adding Lens laws to kategory-test so I left them in optics for now.

@codecov-io
Copy link

codecov-io commented Sep 4, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@543bfbd). Click here to learn what that means.
The diff coverage is 78.12%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #251   +/-   ##
=========================================
  Coverage          ?   50.11%           
  Complexity        ?      247           
=========================================
  Files             ?      114           
  Lines             ?     2558           
  Branches          ?      293           
=========================================
  Hits              ?     1282           
  Misses            ?     1161           
  Partials          ?      115
Impacted Files Coverage Δ Complexity Δ
...ory-optics/src/main/kotlin/kategory/optics/Lens.kt 78.12% <78.12%> (ø) 6 <6> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 543bfbd...0f409b4. Read the comment docs.

@pakoito
Copy link
Member

pakoito commented Sep 4, 2017

Praise be!

object LensLaws {

inline fun <A, B, reified F> laws(lens: Lens<A, B>, aGen: Gen<A>, bGen: Gen<B>, funcGen: Gen<(B) -> B>, EQA: Eq<A>, EQB: Eq<B>, FA: Applicative<F>): List<Law> = listOf(
Law("getSet", { forAll(aGen, { a -> EQA.eqv(lens.set(lens.get(a))(a), a) }) }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these please be separated into functions? They'll read better and you can test them individually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I made the changes. Shall I also move it to kategory-test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raulraja What do you think about merging all tests/laws into a single package? Right now it's supposed to be split per module (effects-tests, recursion-tests, optics-tests) but given that it's not a deployable artifact I don't see any problem making it depend on all the modules and contain all laws.

inline fun <A, B, reified F> laws(lens: Lens<A, B>, aGen: Gen<A>, bGen: Gen<B>, funcGen: Gen<(B) -> B>, EQA: Eq<A>, EQB: Eq<B>, FA: Applicative<F>): List<Law> = listOf(
Law("getSet", { forAll(aGen, { a -> EQA.eqv(lens.set(lens.get(a))(a), a) }) }),
Law("setGet", { forAll(aGen, bGen, { a, b -> EQB.eqv(lens.get(lens.set(b)(a)), b) }) }),
Law("setIdempotent", { forAll(aGen, bGen, { a, b -> EQA.eqv(lens.set(b)(lens.set(b)(a)), lens.set(b)(a)) }) }),
Copy link
Member

@pakoito pakoito Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a more descriptive name for the law, like: "Lens law: is set idempotent". We've been using these through the codebase and they've worked well.

lens = tokenLens,
aGen = TokenGen,
bGen = Gen.string(),
funcGen = Gen.create<(String) -> String> { { it } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already provide a generator for functions, called genFunAtoB IIRC.

@raulraja
Copy link
Member

raulraja commented Sep 4, 2017

@nomisRev Excellent stuff! Excited to have lenses in Kategory and you as maintainer!
giphy

@nomisRev
Copy link
Member Author

nomisRev commented Sep 4, 2017

@raulraja you and me both!

Copy link
Member

@pakoito pakoito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boom! seeing sharp now!

@nomisRev nomisRev merged commit 8c811ef into arrow-kt:master Sep 5, 2017
@wiyarmir wiyarmir mentioned this pull request Sep 15, 2017
rachelcarmena pushed a commit that referenced this pull request Feb 24, 2021
rachelcarmena pushed a commit that referenced this pull request Feb 24, 2021
* Provide nullable { } implementation based on DelimitedScope

* provide singleton object with reference check for nested nullable value.

* Provide extra test cases for nullable.kt

* remove check problems with detekt

* provide TODO for future fun interface

* reduce library visibility for API users.

* nextShift values doesn't need to be nested nullable value.

* Fix warning for parameter renaming for overridden method.

* Eliminate the shift call on non-null values

* move NullableBindSyntax.kt into private inner class for nullable.kt

* fix argument ending

* trigger GitHub actions

* trigger GitHub actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants