Skip to content

Instantly share code, notes, and snippets.

View yoeluk's full-sized avatar

Yoel Garcia Diaz yoeluk

  • Toronto
View GitHub Profile
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
// immutable cycle
class Node[T]( val value: T, _next: => Node[T] ){
lazy val next = _next
}
val cycle: Node[Int] = new Node( 1, new Node( 2, cycle ) )
// prints List(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)
println(cycle.iterator.take(10).map(_.value).toList)
implicit class NodeIterator[T](node: Node[T]){
object StateApply {
import scalaz._
implicit def applyState[F[_], A](implicit F: Applicative[F], S: Semigroup[A]): Applicative[({ type l[a] = StateT[F, A, a]})#l] = new Applicative[({ type l[a] = StateT[F, A, a]})#l] {
def point[B](b: => B): StateT[F, A, B] = StateT[F, A, B]((a:A) => F.point((a,b)))
def ap[B, C](fa: => StateT[F, A, B])(f: => StateT[F, A, B => C]): StateT[F, A, C] = {
StateT[F, A, C]((s: A) => {
val sa = fa.run(s)
val sb = f.run(s)
@yoeluk
yoeluk / streams-tutorial.md
Created November 21, 2015 10:20 — forked from djspiewak/streams-tutorial.md
Introduction to scalaz-stream

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

@yoeluk
yoeluk / Jms.scala
Created March 3, 2016 04:41 — forked from cjjavellana/Jms.scala
Scala Akka Camel Weblogic JMS Sample
import java.util.Properties
import org.apache.camel.component.jms.{ JmsComponent, JmsConfiguration }
import org.springframework.jms.support.destination.JndiDestinationResolver
import org.springframework.jndi.{ JndiObjectFactoryBean, JndiTemplate }
import akka.actor.{ ActorSystem, Props }
import akka.camel.CamelExtension
@yoeluk
yoeluk / BTree.scala
Created December 25, 2017 05:25 — forked from fomkin/BTree.scala
Simple immutable B-tree with Scala
case class BTree[K, V](root: BTree.Node[K, V], order: Int)(implicit keyOrdering: Ordering[K]) {
import keyOrdering.mkOrderingOps
private type N = BTree.Node[K, V]
private type E = BTree.Entry[K, V]
def get(key: K): Option[V] = {
def aux(node: N): Option[V] = {
val mayBeEntry = node.entries.find(_.key == key)
@yoeluk
yoeluk / GNU-Make.md
Created November 28, 2020 16:38 — forked from rueycheng/GNU-Make.md
GNU Make cheatsheet