aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2023-09-18 22:46:23 +0200
committerLouis Pilfold <louis@lpil.uk>2023-09-27 12:33:11 +0100
commit5850112f469beeaa2747f96818e4afec8b69b999 (patch)
tree0dec0e09b16f3c36bae3c47d4bdbc3ab438ca6d9 /test
parentee3045b052a99c6a753d8ddc8b583a643de007e2 (diff)
downloadgleam_stdlib-5850112f469beeaa2747f96818e4afec8b69b999.tar.gz
gleam_stdlib-5850112f469beeaa2747f96818e4afec8b69b999.zip
add `iterator.map2`
Diffstat (limited to 'test')
-rw-r--r--test/gleam/iterator_test.gleam28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam
index 66e8bd4..adb4802 100644
--- a/test/gleam/iterator_test.gleam
+++ b/test/gleam/iterator_test.gleam
@@ -155,6 +155,34 @@ pub fn map_test() {
test([1, 2, 3, 4, 5, 6, 7, 8], f)
}
+// map2(from_list(a), from_list(b), f) == list.map2(a, b, f)
+pub fn map2_test() {
+ let test = fn(one, other, f) {
+ iterator.map2(iterator.from_list(one), iterator.from_list(other), f)
+ |> iterator.to_list
+ |> should.equal(list.map2(one, other, f))
+ }
+
+ let f = fn(a, b) { a / b }
+ test([], [], f)
+ test([], [2, 10, 3], f)
+ test([10], [2, 10, 3], f)
+ test([10, 20], [2, 10, 3], f)
+ test([10, 20, 30], [2, 10, 3], f)
+ test([10, 20, 30], [2, 10], f)
+ test([10, 20, 30], [2], f)
+ test([10, 20, 30], [], f)
+}
+
+pub fn map2_is_lazy_test() {
+ let one = iterator.from_list([])
+ let other = iterator.once(fn() { panic as "unreachable" })
+
+ iterator.map2(one, other, fn(x, y) { x + y })
+ |> iterator.to_list
+ |> should.equal([])
+}
+
// a |> from_list |> flat_map(f) |> to_list ==
// a |> list.map(f) |> list.map(to_list) |> list.concat
pub fn flat_map_test() {