Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I tried unpacking results with use. It is, perhaps, a little tidier than the pipeline syntax: ``` fn write_program(program: program.CompiledProgram) -> Result(Nil, errors.Error) { let build_directory = program.build_directory(program.base_directory) let source_directory = program.source_directory(program.base_directory) use _ <- result.try(output.delete(build_directory)) use _ <- result.try(output.create_directory(build_directory)) use _ <- result.try(output.write_prelude_file(build_directory)) use _ <- result.try(output.write_py_main(build_directory, program.main_module)) use _ <- result.try(output.copy_externals( build_directory, source_directory, program.external_import_files |> set.to_list, )) use state, name, module <- dict.fold(program.modules, Ok(Nil)) { use _ <- result.try(state) build_directory |> filepath.join(name) |> output.replace_extension() |> output.write(module, _) } } ``` Pros of use syntax: * Each `use _ <- result.try` is slightly shorter than `|> result.try(fn(_) {...` * Total line count is marginally smaller and there is less syntax overall Cons: * I had to manually *add back* indentation to make it clear what was happening in the `dict.fold` case. The curlies around the nested expression aren't necessary, but they make it more readable * I have to *think* about how `use` maps to nested dedentation, compared to the explicitness of the pipeline syntax * Even with the extra curlies, it's not as clear to me that the `dict.fold` "pseudo-callback" is called multiple times, but the result.try ones are only called once. Overall, I think the pipeline syntax is marginally easier to *comprehend*, even if the use syntax is marginally easior to *read*.
- Loading branch information