app "roctorrent" packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio.tar.br" } imports [pf.Stdout] provides [main] to pf bDecodeStr: List U8 -> Result (List U8) [Malformatted] bDecodeStr = \i -> when (List.splitFirst i ':') is Ok {before, after} -> when (Str.fromUtf8 before) is Ok ls -> when (Str.toU32 ls) is Ok l -> if Num.toU32 (List.len after) == l then Ok after else Err Malformatted Err _err -> Err Malformatted Err _err -> Err Malformatted Err _err -> Err Malformatted expect res = bDecodeStr (Str.toUtf8 "3:foo") res == Ok (Str.toUtf8 "foo") expect errCases = ["foo", "1:foo", "4:foo", ":", "foo:", "1:", "::"] List.all errCases \t -> res = bDecodeStr (Str.toUtf8 t) res == Err Malformatted main = Stdout.line "Hello, World"