Re: Append or concatenate to each element in sequence

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

Terry Constant wrote:
> 
> Is there a better/faster way to concatenate or append to each element 
> in a sequence than by using a loop, something like illustrated below?
> 
> 
> }}}
<eucode>
> sequence s1
> 
> global function seqConcat(sequence srcSeq, object toAppend)
>   sequence dstSeq, curElement
> 
>   dstSeq = {}
>   for i = 1 to length(srcSeq) do
>     curElement = srcSeq[i] & toAppend
>     dstSeq = append(dstSeq, curElement)
>   end for
>   return dstSeq
> end function  --seqConcat()
> 
> s1 = seqConcat({"abc","def","ghi"}, '\n')
> </eucode>
{{{


You don't need to create a new sequence inside the function: you can just use
srcSeq, like this:
sequence s1

global function seqConcat(sequence srcSeq, object toAppend)
  for i = 1 to length(srcSeq) do
    srcSeq &= toAppend
  end for
  return srcSeq
end function  --seqConcat()

s1 = seqConcat({"abc","def","ghi"}, '\n')


--
tommy online: http://users.telenet.be/tommycarlier
Euphoria Message Board: http://uboard.proboards32.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu