리스트를 받아 각 값마다 (???)를 만드는 함수
함수형 언어에서는 보통 이 연산을 "map"이라고 불러요. Gleam에도 리스트용 map 함수 (https://hexdocs.pm/gleam_stdlib/gleam/list.html#map)가 있는데, 원하시는 작업에 맞는 것 같아요. 예를 들어 이런 식을 쓰면
list.map([2, 3, 4], fn(entry) { "entry: " <> int.to_string(entry) })
변환한 항목을 담은 리스트가 나와요. 그다음 list.intersperse (https://hexdocs.pm/gleam_stdlib/gleam/list.html#intersperse)를 쓰면 각 항목 사이에 다른 항목을 끼워 넣으면서 리스트를 연결할 수 있어요 (함수형 언어 전반에서 그만큼 보편적으로 쓰이는 도우미는 아니에요).
Gleam도 Elixir와 비슷한 파이프라인을 지원하는 듯해서 (https://tour.gleam.run/functions/pipelines/), 저는 아마 이렇게 쓸 거예요
[2, 3, 4]
|> list.map(fn(entry) { "entry: " <> int.to_string(entry) })
|> list.intersperse(", ")
함수형 프로그래밍 전반에서 기본이라고 생각하는 연산 두 가지는 리스트를 하나의 결과로 줄이는 reduce 또는 fold, 그리고 리스트와 조건 함수를 받아 그 조건을 통과한 항목만 담은 리스트를 만드는 filter예요. 이 중 일부는 다른 연산으로 표현할 수 있지만 (특히 fold로 map과 filter를 구현할 수 있어요. 다만 비효율적일 수도 있어요), 제 경험으로는 알맞은 연산을 고르는 편이 이해하기 쉽고 더 빠른 경우도 많아요.
영어에서 번역·원문 보기
a function receiving a list and producing a (???) for every value
Functional languages normally call this operation "map". There is a list function called map in Gleam (https://hexdocs.pm/gleam_stdlib/gleam/list.html#map), which seems to match what you need. For example, with an expression such as
list.map([2, 3, 4], fn(entry) { "entry: " <> int.to_string(entry) })
the result would be a list containing the transformed entries. Afterwards, list.intersperse (https://hexdocs.pm/gleam_stdlib/gleam/list.html#intersperse) lets you join that list with an extra entry placed between successive elements (a helper that isn't nearly as universal in functional languages).
Gleam appears to offer pipelines similar to Elixir's (https://tour.gleam.run/functions/pipelines/), so I'd perhaps express it as
[2, 3, 4]
|> list.map(fn(entry) { "entry: " <> int.to_string(entry) })
|> list.intersperse(", ")
Two more operations that I regard as fundamental across functional programming include reduce or fold, taking a list down to one result, and filter, accepting a list plus a predicate and producing a list containing the entries passing that predicate. Some can be expressed through others (in particular, fold can implement map as well as filter, albeit perhaps inefficiently), but in my experience selecting the appropriate operation is easier to follow and frequently quicker.