From 108d01c3efda55d63193f33e29fb878b07313dfc Mon Sep 17 00:00:00 2001 From: Robert Peterson Date: Thu, 18 Apr 2019 07:41:38 -0700 Subject: Add list:index_map --- test/list_test.gleam | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/list_test.gleam') diff --git a/test/list_test.gleam b/test/list_test.gleam index f9882c0..9c510c4 100644 --- a/test/list_test.gleam +++ b/test/list_test.gleam @@ -1,5 +1,6 @@ import expect import list +import str pub fn length_test() { list:length([]) |> expect:equal(_, 0) @@ -248,3 +249,14 @@ pub fn sort_test() { list:sort([{1,2}, {4,5}, {3,2}]) |> expect:equal(_, [{1,2}, {3,2}, {4,5}]) } + +pub fn index_map_test() { + list:index_map([3,4,5], fn(i, x) { {i, x} }) + |> expect:equal(_, [{0,3},{1,4},{2,5}]) + + let f = fn(i, x) { + str:append(x, str:from_int(i)) + } + list:index_map(["a","b","c"], f) + |> expect:equal(_, ["a0", "b1", "c2"]) +} -- cgit v1.2.3