Skip to content

Commit

Permalink
Improve README and build info.
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-stripe committed Mar 23, 2016
1 parent 20a81de commit 93597f8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
19 changes: 19 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Chain Copyright (c) 2016 Erik Osheim.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 36 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

### Dedication

> all day long they work so hard / 'til the sun is going down
> working on the highways and byways / and wearing, wearing a frown
> you hear them moaning their lives away / then you hear somebody say:
> all day long they work so hard / 'til the sun is going down /
> working on the highways and byways / and wearing, wearing a frown /
> you hear them moaning their lives away / then you hear somebody say: /
>
> that's the sound of the men / working on the chain gang
> that's the sound of the men / working on the chain gang
> that's the sound of the men / working on the chain gang /
> that's the sound of the men / working on the chain gang /
>
> --Sam Cooke, "Chain Gang" (1960)
Expand Down Expand Up @@ -61,16 +61,29 @@ libraryDependencies += "org.spire-math" %%% "chain" % "0.1.0"
### Details

Chain can wrap any `Iterable[A]` values, and support concatenation
between mixed collection types:
between mixed collection types. Here's an example that shows off a
number of Chain's capabilities:

```scala
import chain.Chain

val xs: List[Int] = ...
val ys: Vector[Int] = ...
val zs: Option[Int] = ...

val c = Chain(xs) ++ Chain(ys) ++ Chain(zs)
val ws: Iterable[Int] = List(1,2,3)
val xs: List[Int] = List(4,5,6)
val ys: Vector[Int] = Vector(7,8,9,10,11)
val zs: Option[Int] = Some(12)

val a = Chain(ws) ++ Chain(xs) // no copying
val b = Chain.all(ys, zs) // same as ys ++ zs
val c = 9 +: (a ++ b) :+ 100 // supports prepend/append

c.toVector // Vector(1,2,3,4,5,6,7,8,9,10,11,12)
c.iterator.toList // List(1,2,3,4,5,6,7,8,9,10,11,12)
c.foreach(println) // prints 1-12
c.find(_ > 6) // Some(7)
c.forall(_ >= 0) // true
c.exists(_ > 100) // false
c.map(_ * 2) // Chain(2,4,6,8,10,12,14,16,18,20,22,24)
c.filter(_ % 3 == 0) // Chain(3,6,9,12)
```

Chain is sealed and consists of two concrete case classes:
Expand All @@ -85,6 +98,15 @@ efficiently walk the contents in O(n) time.

Concatenating chains is always O(1), and iteration is always O(n).

Empty Chains can be obtained by `Chain.empty[A]` and are represented
as a singleton `Chain.Empty` which is a `Chain(Nil)`. This value is
immutable and can be shared safely. Chains with a single element are
constructed by `Chain.single(x)` which constructs `Chain(x :: Nil)`
instances. This is done transparently in the case of `+:` and `:+`.
These encoding are relatively efficient although if you are working
entirely with single elements a more efficient data structure is
possible.

Some operations that transform the Chain will need to allocate a new
collection (either directly, or wrapped in a new `Chain[A]`). The
comments explain the exact performance characteristics of each method,
Expand Down Expand Up @@ -136,7 +158,9 @@ towards supporting large collections.

As mentioned above, it would be great to have a story for using type
classes instead of `Iterable[A]` (either via an abstraction or a new
type).
type). It could also be nice to have a version which supported lazy
filtering/mapping (although in many cases this can be emulated with
things like `.iterator.filter`).

### Copyright and License

Expand Down
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReleaseTransformations._
lazy val chainSettings = Seq(
organization := "org.spire-math",
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
homepage := Some(url("http://github.com/striation/chain")),
homepage := Some(url("http://github.com/non/chain")),
scalaVersion := "2.11.8",
crossScalaVersions := Seq("2.10.6", "2.11.8"),
scalacOptions ++= Seq(
Expand All @@ -26,14 +26,14 @@ lazy val chainSettings = Seq(
},
pomExtra := (
<scm>
<url>git@github.com:striation/chain.git</url>
<connection>scm:git:git@github.com:striation/chain.git</connection>
<url>git@github.com:non/chain.git</url>
<connection>scm:git:git@github.com:non/chain.git</connection>
</scm>
<developers>
<developer>
<id>striation</id>
<id>non</id>
<name>Erik Osheim</name>
<url>http://github.com/striation/</url>
<url>http://github.com/non/</url>
</developer>
</developers>
),
Expand Down

0 comments on commit 93597f8

Please sign in to comment.