-
Notifications
You must be signed in to change notification settings - Fork 455
[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
[WIP] selective functor #1335
Conversation
ffa8b37
to
2670b77
Compare
2670b77
to
c005f00
Compare
@@ -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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))})} |
There was a problem hiding this comment.
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) }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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))})} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same whitespace
There was a problem hiding this 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.
Run |
c005f00
to
d12e819
Compare
d5e6c0f
to
251b487
Compare
for #1329
continuing with unfinished tasks, feedback appreciated
Interface definition
Update Monad
Laws
Instances
Tests
Documentation