Packages

I am playing with publishing a package.

Current section

Files

Jump to
playground src group_by_odds_and_evens.gleam
Raw

src/group_by_odds_and_evens.gleam

import gleam/int
import gleam/list
import gleam/string
pub fn group_by_odds_and_evens(numbers: List(Int)) -> String {
let #(xs, ys) = list.fold(numbers, #([], []), folder)
"Odds: " <> format_list(xs) <> ", Evens: " <> format_list(ys)
}
fn folder(acc: #(List(Int), List(Int)), x: Int) {
case is_even(x) {
True -> #(acc.0, [x, ..acc.1])
False -> #([x, ..acc.0], acc.1)
}
}
fn format_list(xs: List(Int)) -> String {
xs |> list.reverse |> list.map(int.to_string) |> string.join(",")
}
fn is_even(x: Int) -> Bool {
x % 2 == 0
}