-
Notifications
You must be signed in to change notification settings - Fork 73
fixes #1293, add zippable to combinators #1307
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e10b2fa
fixes #1293, add zippable to combinators
ahoy-jon 23c5c4c
Update kyo-combinators/shared/src/main/scala/kyo/internal/Zippable.scala
ahoy-jon 9b7b40f
add Zippable.prepend
ahoy-jon 4da1149
scalafmt
ahoy-jon 4c49ed4
full names
ahoy-jon 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
This file contains hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
kyo-combinators/shared/src/main/scala/kyo/internal/Zippable.scala
This file contains hidden or 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,23 @@ | ||
package kyo.internal | ||
|
||
trait Zippable[-A, -B]: | ||
ahoy-jon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type Out | ||
def zip(left: A, right: B): Out | ||
|
||
object Zippable extends ZippableLowPrio0: | ||
|
||
given left[A]: (Zippable[A, Unit] { type Out = A }) = (left: A, _) => left | ||
ahoy-jon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
given right[B]: (Zippable[Unit, B] { type Out = B }) = (_, right: B) => right | ||
|
||
given concat[A <: Tuple, B <: Tuple]: (Zippable[A, B] { type Out = Tuple.Concat[A, B] }) = (left: A, right: B) => left ++ right | ||
|
||
def apply[A, B](using z: Zippable[A, B]): Zippable[A, B] = z | ||
|
||
def zip[A, B](a: A, b: B)(using z: Zippable[A, B]): z.Out = z.zip(a, b) | ||
end Zippable | ||
|
||
trait ZippableLowPrio0 extends ZippableLowPrio1: | ||
ahoy-jon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
given append[A <: Tuple, B]: (Zippable[A, B] { type Out = Tuple.Append[A, B] }) = (left: A, right: B) => left :* right | ||
|
||
trait ZippableLowPrio1: | ||
given pair[A, B]: (Zippable[A, B] { type Out = (A, B) }) = (left: A, right: B) => (left, right) |
33 changes: 33 additions & 0 deletions
33
kyo-combinators/shared/src/test/scala/kyo/internal/ZippableTest.scala
This file contains hidden or 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,33 @@ | ||
package kyo.internal | ||
|
||
import kyo.* | ||
import org.scalatest.compatible.Assertion | ||
|
||
class ZippableTest extends Test: | ||
"compile" - { | ||
def check[A, B](using zip: Zippable[A, B])[Expected](using (zip.Out =:= Expected)): Assertion = succeed | ||
|
||
def on[A, B, C, D]: Assertion = | ||
check[(A, B), (C, D)][(A, B, C, D)] | ||
check[Unit, A][A] | ||
check[Unit, B][B] | ||
check[(A, B), Unit][(A, B)] | ||
check[(A, B), C][(A, B, C)] | ||
end on | ||
|
||
} | ||
|
||
"zip" in { | ||
assert(Zippable.zip(1, 2) == (1, 2)) | ||
assert(Zippable.zip(1, ()) == 1) | ||
assert(Zippable.zip((), 2) == 2) | ||
assert(Zippable.zip((1, 2), 3) == (1, 2, 3)) | ||
assert(Zippable.zip((1, 2), ()) == (1, 2)) | ||
assert(Zippable.zip((), (3, 4)) == (3, 4)) | ||
assert(Zippable.zip((1, 2), (3, 4)) == (1, 2, 3, 4)) | ||
} | ||
|
||
"prepend" in { | ||
assert(Zippable.zip(2, (3, 4)) == (2, (3, 4))) | ||
} | ||
ahoy-jon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end ZippableTest |
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.
Uh oh!
There was an error while loading. Please reload this page.