beamly.core.lang
The Beamly core scala language enhancements. This module only depends on the core Scala libraries.
Getting beamly.core.lang
Add this sbt dependency:
"com.beamly" %% "beamly-core-lang" % "0.5.0"
or maven dependency:
<dependency>
<groupId>com.beamly</groupId>
<artifactId>beamly-core-lang_${scala.binary}</artifactId>
<version>0.5.0</version>
</dependency>
where the scala.binary
variable is either 2.10 or 2.11
Maven Central Repository details
Maturity
We are rapidly approaching 1.0, feel free to provide feedback or raise issues through the github issue tracker.
Quick start
The scaladocs provide full details, but here's a brief summary of some of the key benefits and features.
String utilities
isBlank/nonBlank
methods to check if a string is empty or contains only whitespacetoSnakeCase
which converts a string to snake case, eg: 'nextTvEpisode' to 'next_tv_episode'to<PrimitiveType>Option
which returns a primitive type from a string, converting errors intoNone
Either utilities
map/flatMap
maps Right valuesrecover/flatRecover/recoverWith
converts a Left to a derivation of Right
Option utilities
onSome/onNone
runs a side-effecting function and returns the original result; useful for logging
AtomicReference utilities
update(f: A => A)
attempts to rerun a function to update anAtomicReference
until the update is successful
PartialFunction utilities
andThenWithContext
the same as 'andThen', except the input object is passed as well as the resultcomposePF
the same as 'compose' but returns a PartialFunction
Map utilities
mergeValues
merges 2 maps together, using the provided merge function to create a new map value for a key
Future utilities
promising[A](f: Promise[A] => Any)
creates a promise, uses the provided function to fulfil the promise and then returns the future from the promiseget
orget(10 seconds)
awaits the result of a future with the default timeout of 5 seconds (Await.result
)await
orawait(10 seconds)
awaits the future with the default timeout of 5 seconds (Await.ready
)fold/flatFold
maps successful or failed values to a newFuture
join
method on aFuture[Future[A]]
,Future[Either[Throwable, A]]
orFuture[Try[A]]
flattens the result to aFuture[A]
Future[Option[A]]
Handling a mapOpt[B](f: A => B)
: allows you to simply map aFuture[Option[A]]
without having to callaFuture map { _ map f }
with the far simpler formaFuture mapOpt f
flatMapOpt[B](f: A => Future[Option[B]])
: allows you to simply flatMap aFuture[Option[A]]
without having to callaFuture flatMap { _ map f getOrElse futureNone }
with the far simpler formaFuture flatMapOpt f
orElse[B >: A](other: => Future[Option[B]])
provides an alternativeFuture[Option[B]]
if this result isFuture(None)
Future[Traversable[A]]
Handling a mapTraversable
maps the values in the collection into a newFuture
without having to callaFuture map { _ map f }
License
This software is licensed under the Apache 2.0 License.
Issue Reporting
To report issues with this software, please raise them via the github reporting mechanism.
Contributions
Currently we are not able to accept pull requests, if you wish to contribute please contact us via github.