Re: better flatten()?

new topic     » goto parent     » topic index » view thread      » older message » newer message
jimcbrown said...
petelomax said...

I was also thinking that flatten() should either have a "check for string elements" option or a sister function, at least that was until I did a quick search...

What would this sister function do?

I just meant that instead of an optional flag on the standard flatten(), you could have a similar function that always performed the string checks. I was thinking (given the plan to remove the delimiter)

flatten({{"this","that"},{"the","other"}}) --> "thisthattheother" 
flattens({{"this","that"},{"the","other"}}) --> {"this","that","the","other"} 

However, as I am now thinking that lists of strings, whether you want a delimiter or not, are better passed to join(), any more deeply nested structures that happen to contain strings are likely to contain all other kinds of junk, and passing that sort of thing to flatten() now seems much less likely to yield any kind of useful result no matter how you slice and dice it. If your application has something like { {"this","that"},{"the","other"} } or worse, then it is probably better to roll your own disentangle(), maybe one that sorts and removes duplicates, or only selects those words where some other flag is set, than expect standard routines to have the magic to deal with every possible situation.

Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu