Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

re #10 Made Workbook, Sheet, Row and Cell a Semigroup.

  • Loading branch information...
commit d8b6f7472f8f639c31101566f082768fcefa706f 1 parent 9985496
authored September 06, 2012
2  .gitignore
@@ -6,6 +6,8 @@
6 6
 .buildpath
7 7
 
8 8
 target/
  9
+.lib/
  10
+
9 11
 # the following is for vi and emacs users
10 12
 *~
11 13
 *#
18  pom.xml
@@ -58,6 +58,24 @@
58 58
             <artifactId>scalaz-effect_${scala.version}</artifactId>
59 59
             <version>7.0.0-M3</version>
60 60
         </dependency>
  61
+        <dependency>
  62
+            <groupId>org.scalaz</groupId>
  63
+            <artifactId>scalaz-core_${scala.version}</artifactId>
  64
+            <version>7.0.0-M3</version>
  65
+        </dependency>
  66
+
  67
+        <dependency>
  68
+          <groupId>org.scalacheck</groupId>
  69
+          <artifactId>scalacheck_${scala.version}</artifactId>
  70
+          <version>1.9</version>
  71
+          <scope>test</scope>
  72
+        </dependency>
  73
+        <dependency>
  74
+          <groupId>org.scalaz</groupId>
  75
+          <artifactId>scalaz-scalacheck-binding_${scala.version}</artifactId>
  76
+          <version>7.0.0-M3</version>
  77
+          <scope>test</scope>
  78
+        </dependency>
61 79
     </dependencies>
62 80
 
63 81
     <build>
53  project/Build.scala
... ...
@@ -0,0 +1,53 @@
  1
+import sbt._
  2
+import Project._
  3
+import Keys._
  4
+
  5
+object Build extends Build {
  6
+
  7
+  lazy val buildSettings = Seq(
  8
+    organization       := "thenewmotion",
  9
+    version            := "0.6-SNAPSHOT",
  10
+
  11
+    scalaVersion       := "2.9.2",
  12
+    crossScalaVersions := Seq("2.9.2", "2.10.0-M7"),
  13
+    crossVersion       := CrossVersion.full,
  14
+
  15
+    scalacOptions      := Seq(
  16
+      "-encoding", "UTF-8",
  17
+      "-Ydependent-method-types",
  18
+      "-deprecation",
  19
+      "-unchecked",
  20
+      "-explaintypes"
  21
+    ),
  22
+
  23
+    parallelExecution in Compile := true
  24
+  ) ++ externalPom()
  25
+
  26
+  lazy val repoSettings = Seq(
  27
+    resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository",
  28
+    resolvers += "Releases"  at "http://nexus.thenewmotion.com/content/repositories/releases",
  29
+    resolvers += "Snapshots" at "http://nexus.thenewmotion.com/content/repositories/snapshots"
  30
+  )
  31
+
  32
+  lazy val baseSettings = super.settings ++ Defaults.defaultSettings ++ buildSettings ++ repoSettings
  33
+
  34
+  lazy val standardSettings = baseSettings 
  35
+
  36
+  lazy val parentSettings = standardSettings ++ Seq(
  37
+    fork in Test := false,
  38
+    javaOptions in Test += "-Drun.mode=dev"
  39
+  )
  40
+
  41
+  override lazy val settings = super.settings ++ repoSettings  ++ Seq(
  42
+    shellPrompt := { s => Project.extract(s).currentProject.id + " > " }
  43
+  )
  44
+
  45
+  lazy val excludedTestNames = SettingKey[Seq[String]]("excluded-tests", "temporary excluded tests")
  46
+
  47
+  lazy val poi = Project(
  48
+    id = "poi",
  49
+    base = file("."),
  50
+    settings = parentSettings
  51
+  )
  52
+
  53
+}
1  project/build.properties
... ...
@@ -0,0 +1 @@
  1
+sbt.version=0.12.0
1  project/plugins.sbt
... ...
@@ -0,0 +1 @@
  1
+addSbtPlugin("org.ensime" % "ensime-sbt-cmd" % "0.1.0")
432  sbt.sh
... ...
@@ -0,0 +1,432 @@
  1
+#!/usr/bin/env bash
  2
+#
  3
+# A more capable sbt runner, coincidentally also called sbt.
  4
+# Author: Paul Phillips <paulp@typesafe.com>
  5
+
  6
+# todo - make this dynamic
  7
+declare -r sbt_release_version=0.11.3
  8
+declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
  9
+
  10
+unset sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
  11
+unset scala_version java_home sbt_explicit_version
  12
+unset verbose debug quiet
  13
+
  14
+build_props_sbt () {
  15
+  if [[ -f project/build.properties ]]; then
  16
+    versionLine=$(grep ^sbt.version project/build.properties)
  17
+    versionString=${versionLine##sbt.version=}
  18
+    echo "$versionString"
  19
+  fi
  20
+}
  21
+
  22
+update_build_props_sbt () {
  23
+  local ver="$1"
  24
+  local old=$(build_props_sbt)
  25
+
  26
+  if [[ $ver == $old ]]; then
  27
+    return
  28
+  elif [[ -f project/build.properties ]]; then
  29
+    perl -pi -e "s/^sbt\.version=.*\$/sbt.version=${ver}/" project/build.properties
  30
+    grep -q '^sbt.version=' project/build.properties || echo "sbt.version=${ver}" >> project/build.properties
  31
+
  32
+    echo !!!
  33
+    echo !!! Updated file project/build.properties setting sbt.version to: $ver
  34
+    echo !!! Previous value was: $old
  35
+    echo !!!
  36
+  fi
  37
+}
  38
+
  39
+sbt_version () {
  40
+  if [[ -n $sbt_explicit_version ]]; then
  41
+    echo $sbt_explicit_version
  42
+  else
  43
+    local v=$(build_props_sbt)
  44
+    if [[ -n $v ]]; then
  45
+      echo $v
  46
+    else
  47
+      echo $sbt_release_version
  48
+    fi
  49
+  fi
  50
+}
  51
+
  52
+echoerr () {
  53
+  echo 1>&2 "$@"
  54
+}
  55
+vlog () {
  56
+  [[ $verbose || $debug ]] && echoerr "$@"
  57
+}
  58
+dlog () {
  59
+  [[ $debug ]] && echoerr "$@"
  60
+}
  61
+
  62
+# this seems to cover the bases on OSX, and someone will
  63
+# have to tell me about the others.
  64
+get_script_path () {
  65
+  local path="$1"
  66
+  [[ -L "$path" ]] || { echo "$path" ; return; }
  67
+
  68
+  local target=$(readlink "$path")
  69
+  if [[ "${target:0:1}" == "/" ]]; then
  70
+    echo "$target"
  71
+  else
  72
+    echo "$(dirname $path)/$target"
  73
+  fi
  74
+}
  75
+
  76
+# a ham-fisted attempt to move some memory settings in concert
  77
+# so they need not be dicked around with individually.
  78
+get_mem_opts () {
  79
+  local mem=${1:-1536}
  80
+  local perm=$(( $mem / 4 ))
  81
+  (( $perm > 256 )) || perm=256
  82
+  (( $perm < 1024 )) || perm=1024
  83
+  local codecache=$(( $perm / 2 ))
  84
+  
  85
+  echo "-Xms${mem}m -Xmx${mem}m -XX:MaxPermSize=${perm}m -XX:ReservedCodeCacheSize=${codecache}m"
  86
+}
  87
+
  88
+die() {
  89
+  echo "Aborting: $@"
  90
+  exit 1
  91
+}
  92
+
  93
+make_url () {
  94
+  groupid="$1"
  95
+  category="$2"
  96
+  version="$3"
  97
+  
  98
+  echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar"
  99
+}
  100
+
  101
+declare -r default_jvm_opts="-Dfile.encoding=UTF8"
  102
+declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled"
  103
+declare -r default_sbt_mem=1536
  104
+declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
  105
+declare -r sbt_opts_file=".sbtopts"
  106
+declare -r jvm_opts_file=".jvmopts"
  107
+declare -r latest_28="2.8.2"
  108
+declare -r latest_29="2.9.1"
  109
+declare -r latest_210="2.10.0-SNAPSHOT"
  110
+
  111
+declare -r script_path=$(get_script_path "$BASH_SOURCE")
  112
+declare -r script_dir="$(dirname $script_path)"
  113
+declare -r script_name="$(basename $script_path)"
  114
+
  115
+# some non-read-onlies set with defaults
  116
+declare java_cmd=java
  117
+declare sbt_launch_dir="$script_dir/.lib"
  118
+declare sbt_mem=$default_sbt_mem
  119
+
  120
+# pull -J and -D options to give to java.
  121
+declare -a residual_args
  122
+declare -a java_args
  123
+declare -a scalac_args
  124
+declare -a sbt_commands
  125
+
  126
+build_props_scala () {
  127
+  if [[ -f project/build.properties ]]; then
  128
+    versionLine=$(grep ^build.scala.versions project/build.properties)
  129
+    versionString=${versionLine##build.scala.versions=}
  130
+    echo ${versionString%% .*}
  131
+  fi
  132
+}
  133
+
  134
+execRunner () {
  135
+  # print the arguments one to a line, quoting any containing spaces
  136
+  [[ $verbose || $debug ]] && echo "# Executing command line:" && {
  137
+    for arg; do
  138
+      if printf "%s\n" "$arg" | grep -q ' '; then
  139
+        printf "\"%s\"\n" "$arg"
  140
+      else
  141
+        printf "%s\n" "$arg"
  142
+      fi
  143
+    done
  144
+    echo ""
  145
+  }
  146
+
  147
+  exec "$@"
  148
+}
  149
+
  150
+sbt_groupid () {
  151
+  case $(sbt_version) in
  152
+        0.7.*) echo org.scala-tools.sbt ;;
  153
+       0.10.*) echo org.scala-tools.sbt ;;
  154
+    0.11.[12]) echo org.scala-tools.sbt ;;
  155
+            *) echo org.scala-sbt ;;
  156
+  esac
  157
+}
  158
+
  159
+sbt_artifactory_list () {
  160
+  local version0=$(sbt_version)
  161
+  local version=${version0%-SNAPSHOT}
  162
+  local url="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/$(sbt_groupid)/sbt-launch/"
  163
+  dlog "Looking for snapshot list at: $url "
  164
+  
  165
+  curl -s --list-only "$url" | \
  166
+    grep -F $version | \
  167
+    perl -e 'print reverse <>' | \
  168
+    perl -pe 's#^<a href="([^"/]+).*#$1#;'
  169
+}
  170
+
  171
+make_release_url () {
  172
+  make_url $(sbt_groupid) releases $(sbt_version)
  173
+}
  174
+
  175
+# argument is e.g. 0.13.0-SNAPSHOT
  176
+# finds the actual version (with the build id) at artifactory
  177
+make_snapshot_url () {
  178
+  for ver in $(sbt_artifactory_list); do
  179
+    local url=$(make_url $(sbt_groupid) snapshots $ver)
  180
+    dlog "Testing $url"
  181
+    curl -s --head "$url" >/dev/null
  182
+    dlog "curl returned: $?"
  183
+    echo "$url"
  184
+    return
  185
+  done
  186
+}
  187
+
  188
+jar_url () {
  189
+  case $(sbt_version) in
  190
+             0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
  191
+        *-SNAPSHOT) make_snapshot_url ;;
  192
+                 *) make_release_url ;;
  193
+  esac
  194
+}
  195
+
  196
+jar_file () {
  197
+  echo "$sbt_launch_dir/$1/sbt-launch.jar"
  198
+}
  199
+
  200
+download_url () {
  201
+  local url="$1"
  202
+  local jar="$2"
  203
+  
  204
+  echo "Downloading sbt launcher $(sbt_version):"
  205
+  echo "  From  $url"
  206
+  echo "    To  $jar"
  207
+
  208
+  mkdir -p $(dirname "$jar") && {
  209
+    if which curl >/dev/null; then
  210
+      curl --fail --silent "$url" --output "$jar"
  211
+    elif which wget >/dev/null; then
  212
+      wget --quiet -O "$jar" "$url"
  213
+    fi
  214
+  } && [[ -f "$jar" ]]
  215
+}
  216
+
  217
+acquire_sbt_jar () {
  218
+  sbt_url="$(jar_url)"
  219
+  sbt_jar="$(jar_file $(sbt_version))"
  220
+
  221
+  [[ -f "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
  222
+}
  223
+
  224
+usage () {
  225
+  cat <<EOM
  226
+Usage: $script_name [options]
  227
+
  228
+  -h | -help         print this message
  229
+  -v | -verbose      this runner is chattier
  230
+  -d | -debug        set sbt log level to Debug
  231
+  -q | -quiet        set sbt log level to Error
  232
+  -no-colors         disable ANSI color codes
  233
+  -sbt-create        start sbt even if current directory contains no sbt project
  234
+  -sbt-dir   <path>  path to global settings/plugins directory (default: ~/.sbt/<version>)
  235
+  -sbt-boot  <path>  path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
  236
+  -ivy       <path>  path to local Ivy repository (default: ~/.ivy2)
  237
+  -mem    <integer>  set memory options (default: $sbt_mem, which is
  238
+                       $(get_mem_opts $sbt_mem) )
  239
+  -no-share          use all local caches; no sharing
  240
+  -offline           put sbt in offline mode
  241
+  -jvm-debug <port>  Turn on JVM debugging, open at the given port.
  242
+  -batch             Disable interactive mode
  243
+
  244
+  # sbt version (default: from project/build.properties if present, else latest release)
  245
+  !!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
  246
+  !!! contains an sbt.version property is to update the file on disk.  That's what this does.
  247
+  -sbt-version  <version>   use the specified version of sbt 
  248
+  -sbt-jar      <path>      use the specified jar as the sbt launcher
  249
+  -sbt-snapshot             use a snapshot version of sbt
  250
+  -sbt-launch-dir <path>    directory to hold sbt launchers (default: $sbt_launch_dir)
  251
+
  252
+  # scala version (default: as chosen by sbt)
  253
+  -28                       use $latest_28
  254
+  -29                       use $latest_29
  255
+  -210                      use $latest_210
  256
+  -scala-home <path>        use the scala build at the specified directory
  257
+  -scala-version <version>  use the specified version of scala
  258
+
  259
+  # java version (default: java from PATH, currently $(java -version |& grep version))
  260
+  -java-home <path>         alternate JAVA_HOME
  261
+
  262
+  # jvm options and output control
  263
+  JAVA_OPTS     environment variable holding jvm args, if unset uses "$default_jvm_opts"
  264
+  SBT_OPTS      environment variable holding jvm args, if unset uses "$default_sbt_opts"
  265
+  .jvmopts      if file is in sbt root, it is prepended to the args given to the jvm
  266
+  .sbtopts      if file is in sbt root, it is prepended to the args given to **sbt**
  267
+  -Dkey=val     pass -Dkey=val directly to the jvm
  268
+  -J-X          pass option -X directly to the jvm (-J is stripped)
  269
+  -S-X          add -X to sbt's scalacOptions (-J is stripped)
  270
+
  271
+In the case of duplicated or conflicting options, the order above
  272
+shows precedence: JAVA_OPTS lowest, command line options highest.
  273
+EOM
  274
+}
  275
+
  276
+addJava () {
  277
+  dlog "[addJava] arg = '$1'"
  278
+  java_args=( "${java_args[@]}" "$1" )
  279
+}
  280
+addSbt () {
  281
+  dlog "[addSbt] arg = '$1'"
  282
+  sbt_commands=( "${sbt_commands[@]}" "$1" )
  283
+}
  284
+addScalac () {
  285
+  dlog "[addScalac] arg = '$1'"
  286
+  scalac_args=( "${scalac_args[@]}" "$1" )
  287
+}
  288
+addResidual () {
  289
+  dlog "[residual] arg = '$1'"
  290
+  residual_args=( "${residual_args[@]}" "$1" )
  291
+}
  292
+addResolver () {
  293
+  addSbt "set resolvers in ThisBuild += $1"
  294
+}
  295
+addDebugger () {
  296
+  addJava "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
  297
+}
  298
+get_jvm_opts () {
  299
+  # echo "${JAVA_OPTS:-$default_jvm_opts}"
  300
+  # echo "${SBT_OPTS:-$default_sbt_opts}"
  301
+
  302
+  [[ -f "$jvm_opts_file" ]] && cat "$jvm_opts_file"
  303
+}
  304
+
  305
+process_args ()
  306
+{
  307
+  require_arg () {
  308
+    local type="$1"
  309
+    local opt="$2"
  310
+    local arg="$3"
  311
+    
  312
+    if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
  313
+      die "$opt requires <$type> argument"
  314
+    fi
  315
+  }
  316
+  while [[ $# -gt 0 ]]; do
  317
+    case "$1" in
  318
+       -h|-help) usage; exit 1 ;;
  319
+    -v|-verbose) verbose=1 && shift ;;
  320
+      -d|-debug) debug=1 && shift ;;
  321
+      -q|-quiet) quiet=1 && shift ;;
  322
+
  323
+           -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
  324
+           -mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;;
  325
+     -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
  326
+      -no-share) addJava "$noshare_opts" && shift ;;
  327
+      -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
  328
+       -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
  329
+     -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
  330
+       -offline) addSbt "set offline := true" && shift ;;
  331
+     -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
  332
+         -batch) exec </dev/null && shift ;;
  333
+
  334
+    -sbt-create) sbt_create=true && shift ;;
  335
+  -sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;
  336
+       -sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
  337
+   -sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
  338
+-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
  339
+ -scala-version) require_arg version "$1" "$2" && addSbt "set scalaVersion := \"$2\"" && shift 2 ;;
  340
+    -scala-home) require_arg path "$1" "$2" && addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))" && shift 2 ;;
  341
+     -java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
  342
+
  343
+            -D*) addJava "$1" && shift ;;
  344
+            -J*) addJava "${1:2}" && shift ;;
  345
+            -S*) addScalac "${1:2}" && shift ;;
  346
+            -28) addSbt "++ $latest_28" && shift ;;
  347
+            -29) addSbt "++ $latest_29" && shift ;;
  348
+           -210) addSbt "++ $latest_210" && shift ;;
  349
+
  350
+              *) addResidual "$1" && shift ;;
  351
+    esac
  352
+  done
  353
+  
  354
+  [[ $debug ]] && {
  355
+    case $(sbt_version) in
  356
+     0.7.*) addSbt "debug" ;; 
  357
+         *) addSbt "set logLevel in Global := Level.Debug" ;;
  358
+    esac
  359
+  }
  360
+  [[ $quiet ]] && {
  361
+    case $(sbt_version) in
  362
+     0.7.*) ;; 
  363
+         *) addSbt "set logLevel in Global := Level.Error" ;;
  364
+    esac
  365
+  }
  366
+}
  367
+
  368
+# if .sbtopts exists, prepend its contents to $@ so it can be processed by this runner
  369
+[[ -f "$sbt_opts_file" ]] && {
  370
+  sbtargs=()
  371
+  while IFS= read -r arg; do
  372
+    sbtargs=( "${sbtargs[@]}" "$arg" )
  373
+  done <"$sbt_opts_file"
  374
+
  375
+  set -- "${sbtargs[@]}" "$@"
  376
+}
  377
+
  378
+# process the combined args, then reset "$@" to the residuals
  379
+process_args "$@"
  380
+set -- "${residual_args[@]}"
  381
+argumentCount=$#
  382
+
  383
+# set scalacOptions if we were given any -S opts
  384
+[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""
  385
+
  386
+# Update build.properties no disk to set explicit version - sbt gives us no choice
  387
+[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
  388
+echo "Detected sbt version $(sbt_version)"
  389
+
  390
+[[ -n "$scala_version" ]] && echo "Overriding scala version to $scala_version"
  391
+
  392
+# no args - alert them there's stuff in here
  393
+(( $argumentCount > 0 )) || echo "Starting $script_name: invoke with -help for other options"
  394
+
  395
+# verify this is an sbt dir or -create was given
  396
+[[ -f ./build.sbt || -d ./project || -n "$sbt_create" ]] || {
  397
+  cat <<EOM
  398
+$(pwd) doesn't appear to be an sbt project.
  399
+If you want to start sbt anyway, run:
  400
+  $0 -sbt-create
  401
+
  402
+EOM
  403
+  exit 1
  404
+}
  405
+
  406
+# pick up completion if present; todo
  407
+[[ -f .sbt_completion.sh ]] && source .sbt_completion.sh
  408
+
  409
+# no jar? download it.
  410
+[[ -f "$sbt_jar" ]] || acquire_sbt_jar || {
  411
+  # still no jar? uh-oh.
  412
+  echo "Download failed. Obtain the jar manually and place it at $sbt_jar"
  413
+  exit 1
  414
+}
  415
+
  416
+[[ -n "$sbt_dir" ]] || {
  417
+  sbt_dir=~/.sbt/$(sbt_version)
  418
+  addJava "-Dsbt.global.base=$sbt_dir"
  419
+  echo "Using $sbt_dir as sbt dir, -sbt-dir to override."
  420
+}
  421
+
  422
+# since sbt 0.7 doesn't understand iflast
  423
+(( ${#residual_args[@]} == 0 )) && residual_args=( "shell" )
  424
+
  425
+# run sbt
  426
+execRunner "$java_cmd" \
  427
+  $(get_mem_opts $sbt_mem) \
  428
+  $(get_jvm_opts) \
  429
+  ${java_args[@]} \
  430
+  -jar "$sbt_jar" \
  431
+  "${sbt_commands[@]}" \
  432
+  "${residual_args[@]}"
9  src/main/scala/info/folone/scala/poi/Workbook.scala
@@ -6,7 +6,7 @@ import scalaz.effect.IO
6 6
 package info.folone.scala.poi {
7 7
 
8 8
   class Workbook(sheets: List[Sheet]) {
9  
-
  9
+    val sheetList = sheets
10 10
     private lazy val book = {
11 11
       val workbook = new HSSFWorkbook
12 12
       sheets foreach { sh ⇒
@@ -57,9 +57,9 @@ package info.folone.scala.poi {
57 57
       this
58 58
     }
59 59
 
60  
-    @deprecated("Use safeToFile and unsafePerformIO where you need it")
  60
+    @deprecated("Use safeToFile and unsafePerformIO where you need it", "2012-09-06")
61 61
     def toFile(path: String)           = safeToFile(path).unsafePerformIO
62  
-    @deprecated("Use safeToFile and unsafePerformIO where you need it")
  62
+    @deprecated("Use safeToFile and unsafePerformIO where you need it", "2012-09-06")
63 63
     def toStream(stream: OutputStream) = safeToStream(stream).unsafePerformIO
64 64
 
65 65
     def safeToFile(path: String) = IO {
@@ -95,4 +95,7 @@ package info.folone.scala.poi {
95 95
   }
96 96
   case class Cell(index: Int, data: String)
97 97
   case class CellAddr(sheet: String, row: Int, col: Int)
  98
+
98 99
 }
  100
+
  101
+
24  src/main/scala/info/folone/scala/poi/package.scala
... ...
@@ -0,0 +1,24 @@
  1
+package info.folone.scala
  2
+
  3
+import scalaz._
  4
+
  5
+package object poi {
  6
+  implicit val cellInstance = new Semigroup[Cell] {
  7
+    override def append(f1: Cell, f2: ⇒ Cell) = f2
  8
+  }
  9
+  implicit val rowInstance = new Semigroup[Row] {
  10
+    override def append(f1: Row, f2: ⇒ Row) =
  11
+      Row(f2.index)((f1.cells.map(c => (c.index, c)).toMap ++ f2.cells.map(c => (c.index, c)).toMap)
  12
+                    .map { case(_, y) => y } toList)
  13
+  }
  14
+  implicit val sheetInstance = new Semigroup[Sheet] {
  15
+    override def append(f1: Sheet, f2: ⇒ Sheet) =
  16
+      Sheet(f2.name)((f1.rows.map(r => (r.index, r)).toMap ++ f2.rows.map(r => (r.index, r)).toMap)
  17
+                     .map { case(_, y) => y } toList)
  18
+  }
  19
+  implicit val wbInstance = new Semigroup[Workbook] {
  20
+    override def append(f1: Workbook, f2: ⇒ Workbook) =
  21
+      Workbook((f1.sheetList.map(s => (s.name, s)).toMap ++ f2.sheetList.map(s => (s.name, s)).toMap)
  22
+               .map { case(_, y) => y} toList)
  23
+  }
  24
+}
16  src/test/scala/info/folone/scala/poi/PoiSpec.scala
... ...
@@ -1,8 +1,16 @@
1  
-import org.specs2.mutable._
2  
-package info.folone.scala.poi {
  1
+package info.folone.scala.poi
  2
+
  3
+import scalaz._, syntax.monoid._
3 4
 
4 5
 import org.apache.poi.hssf.usermodel.HSSFSheet
5 6
 import org.specs2.specification.Scope
  7
+import org.specs2.mutable._
  8
+import org.specs2.matcher._
  9
+import org.scalacheck.Properties
  10
+
  11
+import org.scalacheck._
  12
+import scalaz.scalacheck.ScalazProperties._
  13
+import scalaz.scalacheck.ScalaCheckBinding._
6 14
 
7 15
 class PoiSpec extends SpecificationWithJUnit {
8 16
     "Poi" should {
@@ -39,10 +47,8 @@ class PoiSpec extends SpecificationWithJUnit {
39 47
       cellText must beEqualTo("theCell")
40 48
     }
41 49
   }
42  
-
43  
-
  50
+  
44 51
   trait Workbook extends Scope {
45 52
     val book = Workbook(List(Sheet("test")(List(Row(0)(List(Cell(0, "theCell")))))))
46 53
   }
47  
-  }
48 54
 }

0 notes on commit d8b6f74

Please sign in to comment.
Something went wrong with that request. Please try again.