Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to convert an interval into a collection #78

Closed
tartakynov opened this issue Nov 24, 2014 · 3 comments
Closed

Add method to convert an interval into a collection #78

tartakynov opened this issue Nov 24, 2014 · 3 comments

Comments

@tartakynov
Copy link

I think it would be useful to have a method to convert an interval to immutable collection of dates, like SortedSet, with specified step. The main goal is to be able to utilize Scala collections API out of the box

(start to end).toSeq(step).map(date => ???)
@tartakynov tartakynov changed the title Make iterable intervals Add method to convert an interval into a collection Nov 25, 2014
@wookietreiber
Copy link
Contributor

I have been doing something like this, too:

implicit class RichInterval(self: Interval) {
  import org.joda.time.ReadablePeriod

  def by(d: ReadablePeriod) = {
    val coll = collection.mutable.ListBuffer[DateTime]()

    var x = self.start
    while (x < self.end) {
      coll += x
      x += d
    }

    coll.toList
  }
}

@wookietreiber
Copy link
Contributor

I'd be glad to provide a PR on this. Maybe we can even take a builder or so and make it:

def by[Coll](...)(implicit ...): Coll[DateTime] = ???

... like the to[Coll] method in scala collections library.

@wookietreiber wookietreiber mentioned this issue Nov 27, 2014
@gakuzzzz
Copy link
Member

cool 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants