Skip to content

Instantly share code, notes, and snippets.

scala> import scalaz.syntax.bitraverse._
import scalaz.syntax.bitraverse._
scala> import scalaz.std.tuple._
import scalaz.std.tuple._
scala> (List(1,2,3), List("a")).leftMap(_.map(_ + 1))
res0: (List[Int], List[String]) = (List(2, 3, 4),List(a))
@stew
stew / tags.el
Last active August 29, 2015 13:57
* tags
** load-tags-for-this-project
#+begin_src emacs-lisp
(defun find-file-upwards (file-to-find)
"Recursively searches each parent directory starting from the default-directory.
looking for a file with name file-to-find. Returns the path to it
or nil if not found."
(labels
((find-file-r (path)
(let* ((parent (file-name-directory path))
(defun build-package-name (pn d)
(if (null d)
pn
(let ((c (car d)))
(if (equal c "scala")
pn
(build-package-name (concat c "." pn) (cdr d))))))
(defun scala-package-name-from-buffer ()
(let ((l (reverse (split-string (buffer-file-name) "/"))))
This tries to find where the Spec/test of the current buffer lives,
and either creates it, or visits it
#+begin_src emacs-lisp
(defun split-path-of-file (f)
"return dirname.filename" (let ((sp (reverse (split-string f "/"))))
(cons (mapconcat 'identity (reverse (cdr sp)) "/") (car sp))))
(defun scala-test-file-name (f)
(let* ((sp (reverse (split-string f "\\.")))
(h (car sp))
scala> List(BigDecimal(1).some, BigDecimal(13).some, BigDecimal(12).some).sequence.map(_.sum)
res14: Option[scala.math.BigDecimal] = Some(26)
scala> List(BigDecimal(1).some, None, BigDecimal(12).some).sequence.map(_.sum)
res15: Option[scala.math.BigDecimal] = None
@stew
stew / gist:7222113
Created October 29, 2013 20:34
spire example fail
[debug] Waiting for thread run-main to exit
[error] (run-main) java.lang.AbstractMethodError: spire.example.RandomForestExample$$anonfun$1.apply(Ljava/lang/Object;)Ljava/lang/Object;
java.lang.AbstractMethodError: spire.example.RandomForestExample$$anonfun$1.apply(Ljava/lang/Object;)Ljava/lang/Object;
at spire.example.CrossValidation$.loop$1(DataSets.scala:234)
at spire.example.CrossValidation$.crossValidate(DataSets.scala:242)
at spire.example.CrossValidation$.crossValidateClassification(DataSets.scala:259)
at spire.example.RandomForestExample$.testClassification(randomforest.scala:40)
at spire.example.RandomForestExample$delayedInit$body.apply(randomforest.scala:24)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
@stew
stew / scala.el
Created September 3, 2013 14:44
; scala-mode2 found here: https://github.com/hvesalai/scala-mode2 is much better than the scala mode that comes with scalac
(add-to-list 'load-path "~/.emacs.d/scala-mode2/")
(require 'scala-mode)
; http://www.emacswiki.org/emacs/RainbowDelimiters
(add-hook 'scala-mode-hook 'rainbow-delimiters-mode)
; I get ensime from git:
; https://github.com/aemoncannon/ensime
; then run `sbt stage` inside the ensime source directory,
scala> val f : Int => List[Int] = List(_)
f: Int => List[Int] = <function1>
scala> Stream(1,2,3) traverse f
res1: List[scala.collection.immutable.Stream[Int]] = List(Stream(1, ?))
@stew
stew / scala-arrows.el
Created August 4, 2013 00:35
Fancy unicode arrows for emacs scala-mode. Done this way because I don't think it can work as an abbrev.
(defun right-arrow ()
(interactive)
(cond ((looking-back "=")
(backward-delete-char 1) (insert "⇒"))
((looking-back "-")
(backward-delete-char 1) (insert "→"))
(t (insert ">"))))
(defun left-arrow ()
(interactive)
@stew
stew / UnapplyMT.scala
Last active December 19, 2015 20:58
I wrote an Unapply for MonadTrans instances which would catch both things like OptionT[M[_],A] and EitherT[M[_], A, B], then couldn't remember what I was trying to solve by doing it. so I'll just stick it here for now
trait UnapplyMT[TC[_[_[_], _]], N[_], MTNA] {
/** the type constructor */
type MT[_[_], _]
/** The type that MT is applied to */
type A
/** The instance of the type class */
def TC: TC[MT]