Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Jan 24, 2015
1 parent 8f78caa commit 921caf0
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ Whenever possible, it provides alternatives with stronger types to standard libr
return collections of sizes known at compile-time, for example:

```scala
def it = Iterator.fill(nextInt(50))(nextDouble()) // A random iterator...
def it = Iterator.fill(nextInt(50))(nextDouble()) // A random iterator...

def result = it.slidingT(3) // Iterator[(Double, Double, Double)]
// 3 provided as argument at compile-time -> Tuple3 in the return type
def result = it.slidingT(3) // Iterator[(Double, Double, Double)]
// 3 provided as argument at compile-time -> Tuple3 in the return type


val str = "first;second;third;fourth"
val str = "first;second;third;fourth"

val resultOpt = str.splitH(3, ";") // Option[String :: String :: String :: HNil]
// 3 provided as argument at compile-time -> 3-length HList in the return type
val resultOpt = str.splitH(3, ";") // Option[String :: String :: String :: HNil]
// 3 provided as argument at compile-time -> 3-length HList in the return type
```
or that can be repeated, for example:

```scala
val l = List.fill(nextInt(10))(nextDouble()) // A random list...
val l = List.fill(nextInt(10))(nextDouble()) // A random list...

/* Trying to find 5 elements satisfying a predicate */
val result = l.findS(5)(_ > 0.5) // Option[Sized[List[Double], _5]]
// 5 provided as argument at compile-time -> Sized of length 5 in the return type
/* Trying to find 5 elements satisfying a predicate */
val result = l.findS(5)(_ > 0.5) // Option[Sized[List[Double], _5]]
// 5 provided as argument at compile-time -> Sized of length 5 in the return type
```

In the above, `splitH(3, ...)` tries to split `str` into 3 elements. `splitH` ends in `H` so it will
Expand All @@ -41,23 +41,23 @@ or a `Sized` (`Sized[List[Double], _3]`).
The returned values can be matched straight away, like in:

```scala
it.groupedT(2).map{ case (previous, current) => ... }
str.splitT(3, ";") match {
case None => // failed
case Some((first, second, third)) => // success
}
it.groupedT(2).map{ case (previous, current) => ... }

str.splitT(3, ";") match {
case None => // failed
case Some((first, second, third)) => // success
}
```

Whereas using the standard library methods, one would have had to write

```scala
it.grouped(2).withPartial(false).map{ t => (t(0), t(1)) }.map{case (first, second) => ...}
it.grouped(2).withPartial(false).map{ t => (t(0), t(1)) }.map{case (first, second) => ...}

Some(str.split(";", 3)).filter(_.length == 3).map(t => (t(0), t(1), t(2))) match {
case None => ...
case Some((first, second, third)) => ...
}
Some(str.split(";", 3)).filter(_.length == 3).map(t => (t(0), t(1), t(2))) match {
case None => ...
case Some((first, second, third)) => ...
}
```

Available methods are illustrated in the tests, under `src/test`.
Expand All @@ -67,20 +67,24 @@ Available methods are illustrated in the tests, under `src/test`.
Add to your `build.sbt`

```scala
resolvers += Resolver.sonatypeRepo("snapshots")
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)

libraryDependencies += "com.github.alexarchambault" %% "shapeless-refined-std" % "0.1.0-SNAPSHOT"
libraryDependencies +=
"com.github.alexarchambault" %% "shapeless-refined-std" % "0.1.0-SNAPSHOT"
```

Then in your sources:

```scala
import shapeless.refinedstd.syntax._
import shapeless.refinedstd.syntax._

/* New methods ending in ...T (tuples), ...H (HList), or ...S (Sized),
* are available on instances of TraversableOnce, Iterator, TraversableLike,
* IterableLike, SeqLike, String, Regex.
*/
/* New methods ending in ...T (tuples), ...H (HList), or ...S (Sized),
* are available on instances of TraversableOnce, Iterator, TraversableLike,
* IterableLike, SeqLike, String, Regex.
*/
```

Only for scala 2.11 for now, a (possibly lighter) version for scala 2.10 is being prepared. Depends on shapeless 2.1.0-RC1.
Expand All @@ -100,6 +104,6 @@ Clone it and publish it locally prior to compiling shapeless-refined-std.

Thanks to [@milessabin](https://github.com/milessabin/) for the suggestion of the name "shapeless-refined-std".

Copyright (c) 2014 Alexandre Archambault. See LICENSE file for more details.
Copyright (c) 2014-2015 Alexandre Archambault. See LICENSE file for more details.

Released under Apache 2.0 license.

0 comments on commit 921caf0

Please sign in to comment.