kotlin-ports

A port of useful Kotlin functionality to Scala using implicits.

License

License

Categories

Categories

Kotlin Languages
GroupId

GroupId

io.jasonleehodges
ArtifactId

ArtifactId

kotlin-ports_2.12
Last Version

Last Version

0.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

kotlin-ports
A port of useful Kotlin functionality to Scala using implicits.
Project URL

Project URL

https://github.com/jasonleehodges/kotlin-ports
Project Organization

Project Organization

Jason Lee Hodges
Source Code Management

Source Code Management

https://github.com/jasonleehodges/kotlin-ports

Download kotlin-ports_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.jasonleehodges/kotlin-ports_2.12/ -->
<dependency>
    <groupId>io.jasonleehodges</groupId>
    <artifactId>kotlin-ports_2.12</artifactId>
    <version>0.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.jasonleehodges/kotlin-ports_2.12/
implementation 'io.jasonleehodges:kotlin-ports_2.12:0.1.2'
// https://jarcasting.com/artifacts/io.jasonleehodges/kotlin-ports_2.12/
implementation ("io.jasonleehodges:kotlin-ports_2.12:0.1.2")
'io.jasonleehodges:kotlin-ports_2.12:jar:0.1.2'
<dependency org="io.jasonleehodges" name="kotlin-ports_2.12" rev="0.1.2">
  <artifact name="kotlin-ports_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.jasonleehodges', module='kotlin-ports_2.12', version='0.1.2')
)
libraryDependencies += "io.jasonleehodges" % "kotlin-ports_2.12" % "0.1.2"
[io.jasonleehodges/kotlin-ports_2.12 "0.1.2"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.7
org.scalactic : scalactic_2.12 jar 3.0.5

test (1)

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

Project Modules

There are no modules declared in this project.

kotlin-ports

A port of useful Kotlin functionality to Scala using implicits.

SBT use

libraryDependencies += "io.jasonleehodges" % "kotlin-ports_2.12" % "0.1.2"

This package is meant to port useful functionality that I've found in Kotlin over to Scala. The four current pieces include:

  • .single() - this method can be chained at the end of any sequence to pull out the lone item from a single item sequence. If there is not only a single item the method will throw an exception.

  • .singleOrNull() - this method works the same as single() except it returns null in the even that there is not exactly one item in the sequence.

  • repeat - this function is used to repeat a given function n number of times (however many times you pass in as an argument). Example: repeat(5){ println("test") } - this will print test 5 times. This is really useful during unit tests if you need to automate the creation of random objects are api calls or something multiple times.

  • Implicit ternary operator - this is more of a port from Java and it's not exact but it's a nice to have. Example val x = (true) ?? 1 :: 2 will set the variable x to 1 because the boolean value that it implicitly modifies evaluates to true.

Full example:

import io.jasonleehodges.kotlinports.ImplicitSingle._
import io.jasonleehodges.kotlinports.ImplicitTernary._
import io.jasonleehodges.kotlinports.utils._

object main extends App {
  val mylist = List("Single Item")
  (1 + 1 == 2) ?? repeat(5) { println(mylist.single()) } :: println("Too Many Items")
}

Versions

Version
0.1.2
0.1.1