Last active
February 3, 2026 20:22
-
-
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/7afb92919b0705489666e62ca6571d128e2de26
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
| // summary : ZIO learning - using chunks | |
| // keywords : scala, scalacli, chunks, zio, ziotest, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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.4.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