scalax-range-root


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.github.andyglow
ArtifactId

ArtifactId

scalax-range-root_2.12
Last Version

Last Version

0.4
Release Date

Release Date

Type

Type

jar
Description

Description

scalax-range-root
scalax-range-root
Project URL

Project URL

http://github.com/andyglow/scala-range
Project Organization

Project Organization

andyglow
Source Code Management

Source Code Management

https://github.com/andyglow/scala-range

Download scalax-range-root_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.andyglow/scalax-range-root_2.12/ -->
<dependency>
    <groupId>com.github.andyglow</groupId>
    <artifactId>scalax-range-root_2.12</artifactId>
    <version>0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.andyglow/scalax-range-root_2.12/
implementation 'com.github.andyglow:scalax-range-root_2.12:0.4'
// https://jarcasting.com/artifacts/com.github.andyglow/scalax-range-root_2.12/
implementation ("com.github.andyglow:scalax-range-root_2.12:0.4")
'com.github.andyglow:scalax-range-root_2.12:jar:0.4'
<dependency org="com.github.andyglow" name="scalax-range-root_2.12" rev="0.4">
  <artifact name="scalax-range-root_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.andyglow', module='scalax-range-root_2.12', version='0.4')
)
libraryDependencies += "com.github.andyglow" % "scalax-range-root_2.12" % "0.4"
[com.github.andyglow/scalax-range-root_2.12 "0.4"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.10

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.1.1

Project Modules

There are no modules declared in this project.

scala-range

Build Status Maven Central 2.11 Maven Central 2.12 Coverage Status

Install

libraryDependencies += "com.github.andyglow" %% "scalax-range" % Version

Use

import scalax.range._

// numeric
for { x <- inclusive(1) to 10 by 1 } println(x)
(exclusive(1) to 10 by 1) foreach println
(inclusive(0.0) until 1.0 by 0.1) foreach println

// date
import scalax.range.date._
import scala.concurrent.duration.FiniteDuration
import java.time.{Duration => JDuration}

for { d <- inclusive(new java.util.Date(0)) to new java.util.Date(100) by 1 } println(x)
for { d <- inclusive(new java.util.Date(0)) to new java.util.Date(1000000) by 1.second } println(x)
for { d <- inclusive(new java.util.Date(0)) to new java.util.Date(1000000) by JDuration.ofSeconds(1) } println(x)

Introduction

This simple dsl tries to overcome limitation of a standard scala.collection.immutable.Range which is implemented for only Int.

By using scala-range you may leverage the same approach with extended amount of types.

Supported types

All types which has Numeric type-class implemented

  • Byte
  • Char
  • Short
  • Int
  • Long
  • Float
  • Double
  • BigInt
  • BigDecimal For iterating through range of numeric types you need use the same type to specify a step. So Int is the only possible way to traverse through the range of ints, Double for doubles and so on.

For Date related types the step may be defined as java.time.Duration or scala.concurrent.duration.FiniteDuration.

Standard Date & Time related types

  • java.util.Date
  • java.time.Instant
  • java.time.LocalDate
  • java.time.LocalTime
  • java.time.LocalDateTime
  • java.time.OffsetDateTime
  • java.time.ZonedDateTime

JodaTime

JodaTime Date & Time related types

  • org.joda.time.Instant
  • org.joda.time.LocalDate
  • org.joda.time.LocalTime
  • org.joda.time.DateTime

In order to add joda time support please add additional dependency:

libraryDependencies += "com.github.andyglow" %% "scalax-range-joda-time" % Version

Also additional import line will be required:

import scalax.range.jodatime._

This will also make you able to use org.joda.time.Duration as a step definition.

Numerics to define a Step in Date based Ranges

There is also a way to use numeric types to define a step. The way it will be treated is different for different types used to define a range. Basically the numeric will get converted into Long and then this long gets treated uniquely.

  • java.util.Date (num is seconds)
  • java.time.Instant (num is seconds)
  • java.time.LocalDate (num is days)
  • java.time.LocalTime (num is minutes)
  • java.time.LocalDateTime (num is hours)
  • java.time.OffsetDateTime (num is hours)
  • java.time.ZonedDateTime (num is hours)
  • org.joda.time.Instant (num is seconds)
  • org.joda.time.LocalDate (num is days)
  • org.joda.time.LocalTime (num is minutes)
  • org.joda.time.DateTime (num is hours)

TODO:

Versions

Version
0.4
0.2
0.1