Last active
May 6, 2023 15:39
-
-
Save dacr/5f549958e2733bee53a46bced8ba47a7 to your computer and use it in GitHub Desktop.
ZIO learning - using chunks / published by https://github.com/dacr/code-examples-manager #32aa6700-5da8-4ab9-a457-5283dd5026ba/99692157faa848519fe8a74b348e67eae4278929
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
// summary : ZIO learning - using chunks | |
// keywords : scala, scalacli, chunks, zio, ziotest, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 32aa6700-5da8-4ab9-a457-5283dd5026ba | |
// created-on : 2021-11-11T19:38:15+01:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
//> using scala "3.2.2" | |
//> using dep "dev.zio::zio:2.0.13" | |
//> using dep "dev.zio::zio-test:2.0.13" | |
import zio._ | |
import zio.test._ | |
import zio.test.Assertion._ | |
object Encapsulated extends ZIOSpecDefault { | |
val testLogic = suite("chunk tests")( | |
test("chunk head") { | |
ZIO.attempt(assertTrue(Chunk.single(42).head == 42)) | |
}, | |
test("chunk has a size") { | |
ZIO.attempt(assertTrue(Chunk(1, 2, 3, 4, 5).size == 5)) | |
}, | |
test("chunk is mappable") { | |
ZIO.attempt( | |
assertTrue(Chunk.fromIterable(1 to 5).map(_ + 1).sum == (2 to 6).sum) | |
) | |
}, | |
test("chunks are zippable") { | |
ZIO.attempt( | |
assertTrue( | |
Chunk | |
.fromArray("abcd".toArray) | |
.zip(Chunk.fromIterable(1 to 2)) == Chunk('a' -> 1, 'b' -> 2) | |
) | |
) | |
}, | |
test("And chunks are very fast because backed by arrays") { | |
ZIO.attempt(assertTrue(Chunk.fill(42424242)(42L).size == 42424242)) | |
} | |
) | |
def spec = testLogic | |
} | |
Encapsulated.main(Array.empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment