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
/** | |
* DERIVING THE Y COMBINATOR IN 7 EASY STEPS | |
* | |
* Ionut G. Stan | ionut.g.stan@gmail.com | http://igstan.ro | http://twitter.com/igstan | |
* | |
* | |
* The Y combinator is a method of implementing recursion in a programming | |
* language that does not support it natively (actually, it's used more for | |
* exercising programming brains). The requirement is the language to support | |
* anonymous functions. |
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 <pthread.h> | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
static uint8_t code[] = { | |
0x40, 0x05, 0x80, 0x52, // mov w0, #3 | |
0xc0, 0x03, 0x5f, 0xd6, // ret |
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
module Seq = struct | |
include Seq | |
let rec fold_right : 'a Seq.t -> 'b -> ('a -> 'b Lazy.t -> 'b Lazy.t) -> 'b Lazy.t = | |
fun seq acc f -> | |
match seq () with | |
| Seq.Nil -> lazy acc | |
| Seq.Cons (a, rest) -> f a (lazy (Lazy.force (fold_right rest acc f))) | |
let map : ('a -> 'b) -> 'a Seq.t -> 'b Seq.t = |
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 ro.igstan.playground; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class MoneyTest { | |
public static interface Money<E extends Money<E>> { | |
public static final class Zero<E extends Money<E>> implements Money<E> { | |
@Override |
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 SACVisitor[R] { | |
def c1(a: Int): R | |
def c2(a: R, b: R): R | |
} | |
sealed trait SAC extends Product with Serializable { | |
def fold[R](visitor: SACVisitor[R]): R | |
} | |
object SAC { |
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
<?php | |
/** | |
* Copyright (c) 2009, Ionut Gabriel Stan. All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without modification, | |
* are permitted provided that the following conditions are met: | |
* | |
* * Redistributions of source code must retain the above copyright notice, | |
* this list of conditions and the following disclaimer. | |
* |
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
{-# LANGUAGE DeriveFunctor #-} | |
import Control.Applicative | |
import Control.Monad.Writer | |
import Control.Monad.Reader | |
import Control.Monad.Identity | |
import Data.Map (Map, (!)) | |
import qualified Data.Map as Map | |
import Data.List (groupBy, intercalate, nub) | |
import Data.Function (on) |
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
import cats.implicits._ | |
import cats.Monad | |
import cats.data.State | |
// | |
// Two capability/tagless final traits: Foo & Bar | |
// | |
trait Foo[F[_]] { | |
def foo: F[Unit] | |
} |
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
$ ./to-csv.sed records.xml | |
111111H2,111AA2026 | |
111111N1,111AA2026 | |
111111Q1,111AA2026 | |
111111U1,111AA2026 | |
111111Z1,111AA2026 |
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
import cats.Eq | |
import monix.reactive.Observable | |
import monix.execution.Scheduler.Implicits.global | |
object Main { | |
implicit final class ObservableOps[A](private val self: Observable[A]) extends AnyVal { | |
def bubbleUpHot(a: A)(implicit Eq: Eq[A]): Observable[A] = | |
self.publishSelector { hot => | |
val special = hot.find(_ === a) | |
val beforeSpecial = hot.takeWhile(_ =!= a) |
NewerOlder