Skip to content

Instantly share code, notes, and snippets.

View igstan's full-sized avatar

Ionuț G. Stan igstan

View GitHub Profile
signature TAGGED_ORD =
sig
type t
type a
val wrap : int -> t
val compare : t * t -> order
val asRecord : { wrap : a -> t, compare : t * t -> order }
end
functor Member(Flag : sig type t end) =
struct
(* Define types and values common to both MemberA and MemberB. *)
end
(*
* MemberA and MemberB differ only in the declaration of Flag, the rest of
* the types and values are the same and come from the Member functor.
*)
structure MemberA =
function required(name) {
return process.env[name] || (
console.error('Missing required environment variable:', name), // <-- this
process.exit(1)
);
}
nth :: Int -> [a] -> a
nth n xs =
let
f acc 0 = acc
f acc n = acc . tail
in
head $ foldl f id [0..n] xs
@igstan
igstan / visitor.py
Last active November 20, 2015 09:36 — forked from danoneata/visitor.py
Visitor pattern in Python
class Expr(object):
def accept(self, visitor):
method_name = 'visit_{}'.format(self.__class__.__name__.lower())
visit = getattr(visitor, method_name)
return visit(self)
class Int(Expr):
def __init__(self, value):
self.value = value
import com.twitter.finagle.Http
import com.twitter.util.Await
import io.finch._
import io.finch.response.EncodeResponse.encodeString
import io.finch.circe._
object Main {
val hello: Endpoint[String] =
get("hello") {
object Main {
// libraryDependencies += "com.typesafe.play" %% "play-json" % "2.3.9"
import play.api.libs.json._
// Domain objects
sealed trait RankedContent
case class Tweet(tweet: Int) extends RankedContent
case class Link(link: Int) extends RankedContent
case class Response(rank: Int, tag: String, rankedcontent: List[RankedContent])
import java.util.Optional;
import java.util.function.Function;
public class Chain {
public static interface Function2<A,B,R> {
public R apply(A a, B b);
}
public static interface Function3<A,B,C,R> {
public R apply(A a, B b, C c);
/*
* Assume you have a bunch of methods that return `Option` and you want to
* produce very precise output about which of those methods returned a `None`
* in case of "failure".
*
* There are a few strategies to doing that. Here are three of them:
*/
object Main {
def foo: Option[String] = Some("foo")
def bar(x: String): Option[String] = None