-
Notifications
You must be signed in to change notification settings - Fork 451
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
Move Optics std to companion objects #888
Merged
Merged
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
7fe7a80
Std as companion
nomisRev 45115fa
Update Option
nomisRev aa42791
Update String
nomisRev 51d5b28
Update Either
nomisRev bb3519b
Update List
nomisRev 9649ea2
Update Map
nomisRev fd1a5f4
Update NonEmptyList
nomisRev ea00af1
Update Set
nomisRev e397c33
Update Try
nomisRev 53b3ab1
Update Tuple
nomisRev b44fa48
Update Validated
nomisRev 96bd72f
Update Id
nomisRev 4c6b8a7
Update SequenceK
nomisRev 7b400bc
Update docs
nomisRev b50d4a7
Detekt fixes
nomisRev 44b5760
Use correct Eq instance for SequenceKInstanceTest
nomisRev 67334b1
Merge branch 'master' into simon-std-on-companion
nomisRev bc20b00
Merge branch 'master' into simon-std-on-companion
nomisRev d9e9baf
Fix optics law links
nomisRev 0faf984
Merge branch 'master' into simon-std-on-companion
pakoito d9b5fec
Merge branch 'master' into simon-std-on-companion
nomisRev 3c9a69f
Merge branch 'simon-std-on-companion' of github.com:arrow-kt/arrow in…
nomisRev dcbd3b7
Move List std to ListInstances
nomisRev de469fa
Move Set std to SetInstances
nomisRev 2d5c0ad
Fix KDoc optics.std.Option
nomisRev 513a6e3
Hygiene - Use method reference where applicable
nomisRev 41dd06b
Add missing test NonEmptyList
nomisRev 6726731
Detekt fix
nomisRev 628a742
Merge branch 'master' into simon-std-on-companion
pakoito afe1d2f
Merge branch 'master' into simon-std-on-companion
pakoito 369a890
Move Instances objects to arrow-core
nomisRev 60823d7
Add List optics instances to ListInstances
nomisRev dd0b002
Add Map optics instances to MapInstances
nomisRev e53b8f2
Merge branch 'master' into simon-std-on-companion
nomisRev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
modules/core/arrow-instances-data/src/main/kotlin/arrow/instances/list.kt
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,3 @@ | ||
package arrow.instances | ||
|
||
object ListInstances | ||
72 changes: 1 addition & 71 deletions
72
modules/core/arrow-instances-data/src/main/kotlin/arrow/instances/set.kt
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 |
---|---|---|
@@ -1,73 +1,3 @@ | ||
package arrow.instances | ||
|
||
import arrow.Kind | ||
import arrow.core.Eval | ||
import arrow.data.* | ||
import arrow.instance | ||
import arrow.typeclasses.* | ||
import arrow.data.combineK as setCombineK | ||
import kotlin.collections.plus as setPlus | ||
|
||
@instance(SetK::class) | ||
interface SetKSemigroupInstance<A> : Semigroup<SetK<A>> { | ||
override fun SetK<A>.combine(b: SetK<A>): SetK<A> = | ||
(this.setPlus(b)).k() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKMonoidInstance<A> : SetKSemigroupInstance<A>, Monoid<SetK<A>> { | ||
override fun empty(): SetK<A> = emptySet<A>().k() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKEqInstance<A> : Eq<SetK<A>> { | ||
|
||
fun EQ(): Eq<A> | ||
|
||
override fun SetK<A>.eqv(b: SetK<A>): Boolean = | ||
if (size == b.size) set.map { aa -> | ||
b.find { bb -> EQ().run { aa.eqv(bb) } } != null | ||
}.fold(true) { acc, bool -> | ||
acc && bool | ||
} | ||
else false | ||
|
||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKShowInstance<A> : Show<SetK<A>> { | ||
override fun SetK<A>.show(): String = | ||
toString() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKFoldableInstance : Foldable<ForSetK> { | ||
override fun <A, B> Kind<ForSetK, A>.foldLeft(b: B, f: (B, A) -> B): B = | ||
fix().foldLeft(b, f) | ||
|
||
override fun <A, B> Kind<ForSetK, A>.foldRight(lb: Eval<B>, f: (A, Eval<B>) -> Eval<B>): Eval<B> = | ||
fix().foldRight(lb, f) | ||
|
||
override fun <A> Kind<ForSetK, A>.isEmpty(): kotlin.Boolean = | ||
fix().isEmpty() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKSemigroupKInstance : SemigroupK<ForSetK> { | ||
override fun <A> Kind<ForSetK, A>.combineK(y: Kind<ForSetK, A>): SetK<A> = | ||
fix().setCombineK(y) | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKMonoidKInstance : MonoidK<ForSetK> { | ||
override fun <A> empty(): SetK<A> = | ||
SetK.empty() | ||
|
||
override fun <A> Kind<ForSetK, A>.combineK(y: Kind<ForSetK, A>): SetK<A> = | ||
fix().setCombineK(y) | ||
} | ||
|
||
object SetKContext : SetKFoldableInstance, SetKMonoidKInstance | ||
|
||
infix fun <A> ForSetK.Companion.extensions(f: SetKContext.() -> A): A = | ||
f(SetKContext) | ||
object SetInstances | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as ListInstances! We could also add the others: Map, SortedMap, and SortedSet. |
73 changes: 73 additions & 0 deletions
73
modules/core/arrow-instances-data/src/main/kotlin/arrow/instances/setk.kt
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,73 @@ | ||
package arrow.instances | ||
|
||
import arrow.Kind | ||
import arrow.core.Eval | ||
import arrow.data.* | ||
import arrow.instance | ||
import arrow.typeclasses.* | ||
import arrow.data.combineK as setCombineK | ||
import kotlin.collections.plus as setPlus | ||
|
||
@instance(SetK::class) | ||
interface SetKSemigroupInstance<A> : Semigroup<SetK<A>> { | ||
override fun SetK<A>.combine(b: SetK<A>): SetK<A> = | ||
(this.setPlus(b)).k() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKMonoidInstance<A> : SetKSemigroupInstance<A>, Monoid<SetK<A>> { | ||
override fun empty(): SetK<A> = emptySet<A>().k() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKEqInstance<A> : Eq<SetK<A>> { | ||
|
||
fun EQ(): Eq<A> | ||
|
||
override fun SetK<A>.eqv(b: SetK<A>): Boolean = | ||
if (size == b.size) set.map { aa -> | ||
b.find { bb -> EQ().run { aa.eqv(bb) } } != null | ||
}.fold(true) { acc, bool -> | ||
acc && bool | ||
} | ||
else false | ||
|
||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKShowInstance<A> : Show<SetK<A>> { | ||
override fun SetK<A>.show(): String = | ||
toString() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKFoldableInstance : Foldable<ForSetK> { | ||
override fun <A, B> Kind<ForSetK, A>.foldLeft(b: B, f: (B, A) -> B): B = | ||
fix().foldLeft(b, f) | ||
|
||
override fun <A, B> Kind<ForSetK, A>.foldRight(lb: Eval<B>, f: (A, Eval<B>) -> Eval<B>): Eval<B> = | ||
fix().foldRight(lb, f) | ||
|
||
override fun <A> Kind<ForSetK, A>.isEmpty(): kotlin.Boolean = | ||
fix().isEmpty() | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKSemigroupKInstance : SemigroupK<ForSetK> { | ||
override fun <A> Kind<ForSetK, A>.combineK(y: Kind<ForSetK, A>): SetK<A> = | ||
fix().setCombineK(y) | ||
} | ||
|
||
@instance(SetK::class) | ||
interface SetKMonoidKInstance : MonoidK<ForSetK> { | ||
override fun <A> empty(): SetK<A> = | ||
SetK.empty() | ||
|
||
override fun <A> Kind<ForSetK, A>.combineK(y: Kind<ForSetK, A>): SetK<A> = | ||
fix().setCombineK(y) | ||
} | ||
|
||
object SetKContext : SetKFoldableInstance, SetKMonoidKInstance | ||
|
||
infix fun <A> ForSetK.Companion.extensions(f: SetKContext.() -> A): A = | ||
f(SetKContext) |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you please put this file in arrow-data instead? That way we don't need to depend on the instances package when adding other typeclasses to List.
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.
Shouldn't these go to
arrow-core
?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.
It's cheap so why not :D