Skip to content

[WIP] selective functor #1335

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

Merged
merged 6 commits into from
Mar 8, 2019
Merged

Conversation

richard-gibson
Copy link
Contributor

@richard-gibson richard-gibson commented Mar 8, 2019

for #1329
continuing with unfinished tasks, feedback appreciated

@@ -49,7 +50,8 @@ class OptionTest : UnitSpec() {
TraverseFilterLaws.laws(Option.traverseFilter(), Option.applicative(), ::Some, Eq.any()),
MonadFilterLaws.laws(Option.monadFilter(), ::Some, Eq.any()),
HashLaws.laws(Option.hash(Int.hash()), Option.eq(Int.eq())) { it.some() },
SemigroupalLaws.laws(Option.semigroupal(), ::Some, ::bijection, associativeSemigroupalEq)
SemigroupalLaws.laws(Option.semigroupal(), ::Some, ::bijection, associativeSemigroupalEq),
SelectiveLaws.laws(Option.selective(), Eq.any())
Copy link
Member

Choose a reason for hiding this comment

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

This is not necessary as MonadFilterLaws already check SelectiveLaws. Same for the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, will remove. In that case I should remove all selective instances if there is a monad instance available too

@extension
interface Function0Selective : Selective<ForFunction0>, Function0Applicative {
override fun <A, B> Function0Of<Either<A, B>>.select(f: Kind<ForFunction0, (A) -> B>): Kind<ForFunction0, B> =
fix().flatMap { it.fold({l -> just(l).ap(f)}, {r -> just(identity(r))})}
Copy link
Member

Choose a reason for hiding this comment

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

Typo: additional whitespace. Format it with IntelliJ.


fun <F> laws(A: Selective<F>, EQ: Eq<Kind<F, Int>>): List<Law> =
ApplicativeLaws.laws(A, EQ) + listOf(
Law("Selective Laws: identity") { A.identityLaw(EQ) },
Copy link
Member

Choose a reason for hiding this comment

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

Did they have more descriptive names on the paper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Distributivity, Associativity, selectM == select if a Monad.
I can add.

@extension
interface OptionSelective : Selective<ForOption>, OptionApplicative {
override fun <A, B> OptionOf<Either<A, B>>.select(f: OptionOf<(A) -> B>): Option<B> =
fix().flatMap { it.fold({l -> just(l).ap(f)}, {r -> just(identity(r))})}
Copy link
Member

Choose a reason for hiding this comment

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

Same whitespace

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.

So far so good! I'm happy with merging as-is once the detek issues and that unnecessary test are fixed.

@pakoito
Copy link
Member

pakoito commented Mar 8, 2019

UnusedImports - [IdTest.kt] at /home/travis/build/arrow-kt/arrow/modules/core/arrow-core-data/src/test/kotlin/arrow/core/IdTest.kt:20:1

Run detekt locally I say. ./gradlew clean detekt

@pakoito pakoito merged commit 475f113 into arrow-kt:master Mar 8, 2019
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.

3 participants