Bober02
Bober02

Reputation: 15351

Scala - simple tuple generation

I am trying to generate N tuples, where the first element is the relative time from the (start + i mins) and the second is the content with the corresponding id appended at the end. My code looks a bit messy to me, I was hop[ing maybe somene could point out some operators/methods which might be more concise. Here's what I have so far:

1 to messageCount map (i => start.plusMinutes(i)) zip (1 to messageCount map (i => message + i))

Upvotes: 0

Views: 106

Answers (1)

gzm0
gzm0

Reputation: 14842

How about this:

for (i <- 1 to messageCount)
  yield (start.plusMinutes(i), message + 1)

IMHO you don't need the zip in this case, it even makes it look more complicated than it is.

Upvotes: 3

Related Questions