This question is about functional programming, not about how to build URL query strings. The language I’m working in is Objective-C but that’s also not especially relevant.
I have a starting data structure that’s an array of strings. Each odd element is the parameter name, each even one is the value eg, [firstname, bob, lastname, smith, gender, male].
Is there an idiomatic FP approach to converting this list into a URL query string (eg. “firstname=bob&lastname=smith&gender=male”)?
I’m thinking something along the lines of ‘partition using a mod 2 predicate’ to give me 2 lists of keys and values respectively, then zipWith a function that url escapes the keys and values and joins them with ‘=’. That will give me a list of ‘a=b’ strings. Then I should be able to do a fold-left to insert the ‘&’ symbols.
I think I may have just answered my own question! Sweet! Posting it anyway in case someone more familiar with FP idioms wants to comment.
Thanks!
Here’s a more-or-less direct translation of your English into C#: