How to translate this piece of Golang code to Elixir?

Pointing to recursion, comprehensions, and higher-order functions only help so much. They tell us what the desired result will look like, or should look like, but not how to get there :confused:

@AlecHsueh Once you know what you’re doing, whether that’s by reading that particular Go fragment or not, then you can give it a go in Elixir. It’s hard to get rid of the for and the mutation with a line-by-line translation but understanding it helps to get to something that’s more Elixir-like.

There’s a collection of some kind underlying most fragments that have a C-like for. A brief glance at the above suggests that it involves byte manipulation or binary data. An Elixir Binary, along with a binary comprehension, and a bunch of meaningful functions might be an idiomatic choice here :slight_smile:

I hope that helps: it’s a great exercise.

3 Likes