Giter Site home page Giter Site logo

scalaj's Introduction

ScalaJ Converters Build Status Coverage Status

When JavaConverters is not enough...

If you work on a Java/Scala mixed project you can find yourself converting java collections and/or primitive wrappers to/from corresponding scala classes or vice versa. JavaConverters is your friend here, but it's not always good enough.

If you are tired of doing something like this

import scala.jdk.CollectionConverters._

def iTakeInt(i: Int) = { ... }

val something = someJavaListOfJavaIntegers.asScala.map(iTakeInt(_))

or this

import scala.jdk.CollectionConverters._

val something: mutable.Map[java.lang.Long, Buffer] = 
  someJavaMapOfJavaLongsToJavaLists.asScala.mapValues(_.asScala)

look no more!
Now you can do

import com.daodecode.scalaj.collection._

def iTakeInt(i: Int) = { ... }

val something = someJavaListOfJavaIntegers.deepAsScala.map(iTakeInt)

and

import com.daodecode.scalaj.collection._

val something: mutable.Map[Long, Buffer] = 
  someJavaMapOfJavaLongsToJavaLists.deepAsScala

ScalaJ Converters will go all the way down converting every nested collection or primitive type.
Of course you should be ready to pay some cost for all these conversions.

Import import com.daodecode.scalaj.collection._ aslo brings standard JavaConverters._ in scope, so you can use plain asJava/asScala if you don't have nested collections or collections of primitives.

Having scalaj-googloptional in classpath you can add guava Optionals to your funky data structures and convert between them and scala versions all the way down and back.

val foo: java.util.Set[Optional[java.lang.Double] = ...

import com.daodecode.scalaj.googleoptional._

val scalaFoo: mutable.Set[Option[Double]] = foo.deepAsScala

If you want you scala collections well-done immutable, you can do it as well

val boo: java.util.Set[Optional[java.util.List[java.lang.Double]] = ...

import com.daodecode.scalaj.googleoptional._
import com.daodecode.scalaj.collection.immutable._

val immutableScalaBoo: Set[Option[immutable.Seq[Double]]] = boo.deepAsScalaImmutable

Latest stable release

scalaj-collection

2.10 2.11 2.12 2.13 3
Maven Central Maven Central Maven Central Maven Central Maven Central

sbt

libraryDependencies += "com.daodecode" %% "scalaj-collection" % "0.3.2"

maven

set <scala.binary.version> property to scala version you need, like

<properties>
    <scala.binary.version>2.13</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-collection_${scala.binary.version}</artifactId>
    <version>0.3.2</version>
</dependency>

scalaj-googleoptional

2.10 2.11 2.12 2.13 3
Maven Central Maven Central Maven Central Maven Central Maven Central

sbt

libraryDependencies += "com.daodecode" %% "scalaj-googleoptional" % "0.3.2"

maven

<properties>
    <scala.binary.version>2.13</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-googleoptional_${scala.binary.version}</artifactId>
    <version>0.3.2</version>
</dependency>

Latest snapshot

First add sonatype snapshots repository to your settings

sbt

resolvers += Resolver.sonatypeRepo("snapshots")

maven

<repository>
    <id>snapshots-repo</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases><enabled>false</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
</repository>

then add snapshot as a dependency

scalaj-collection

sbt

libraryDependencies += "com.daodecode" %% "scalaj-collection" % "0.3.3-SNAPSHOT"

maven

<properties>
    <scala.binary.version>2.13</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-collection_${scala.binary.version}</artifactId>
    <version>0.3.3-SNAPSHOT</version>
</dependency>

scalaj-googleoptional

sbt

libraryDependencies += "com.daodecode" %% "scalaj-googleoptional" % "0.3.3-SNAPSHOT"

maven

<properties>
    <scala.binary.version>2.13</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-googleoptional_${scala.binary.version}</artifactId>
    <version>0.3.3-SNAPSHOT</version>
</dependency>

Related projects

https://github.com/softprops/guavapants

https://github.com/scalaj/scalaj-collection

scalaj's People

Contributors

bitdeli-chef avatar jozic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nu11ptr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.