This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package scalaz.example | |
| object RunLengthEncoder extends App { | |
| import scalaz._ | |
| import scalaz.std.option._ | |
| import scalaz.std.anyVal._ | |
| import scalaz.syntax.show._ | |
| import scalaz.syntax.apply._ | |
| /* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module natToBin | |
| data Parity : Nat -> Type where | |
| even : Parity (n + n) | |
| odd : Parity (S (n + n)) | |
| parity : (n:Nat) -> Parity n | |
| natToBin : Nat -> List Bool | |
| natToBin Z = Nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module partition | |
| %default total | |
| even : Nat -> Bool | |
| even x = (mod x 2) == 0 | |
| partition' : (a -> Bool) -> List a -> List a | |
| partition' f [] = [] | |
| partition' f (x :: xs) with (partition' f xs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scalaz._ | |
| import scalaz.std.list._ | |
| import scalaz.syntax.traverse._ | |
| import scalaz.State._ | |
| trait Main { | |
| type TypeEnvironment | |
| case class GetTypeEnvironment(get: TypeEnvironment) | |
| case class Processor(after: GetTypeEnvironment) | |
| def performTypeInference(typeEnv: TypeEnvironment, next: Processor): Processor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| java.lang.StackOverflowError | |
| at scalaz.syntax.ShowOps.<init>(ShowSyntax.scala:5) | |
| at scalaz.syntax.ToShowOps$class.ToShowOps(ShowSyntax.scala:16) | |
| at scalaz.Scalaz$.ToShowOps(Scalaz.scala:3) | |
| at scalaz.example.CABRunLengthEncoder$.writeOutput(ReaderWriterStateTUsage.scala:143) | |
| at scalaz.example.CABRunLengthEncoder$$anonfun$emit$1$$anonfun$apply$7$$anonfun$4.apply(ReaderWriterStateTUsage.scala:154) | |
| at scalaz.example.CABRunLengthEncoder$$anonfun$emit$1$$anonfun$apply$7$$anonfun$4.apply(ReaderWriterStateTUsage.scala:154) | |
| at scalaz.std.OptionFunctions$class.cata(Option.scala:179) | |
| at scalaz.std.option$.cata(Option.scala:231) | |
| at scalaz.syntax.std.OptionOps.cata(OptionOps.scala:9) |