Skip to content

Instantly share code, notes, and snippets.


Ionuț G. Stan igstan

View GitHub Profile
igstan / kind-polymorphism.scala
Last active May 16, 2018 — forked from szeiger/gist:3a2e7e65b641bac9764a9c02de233ab9
Kind-polymorphic Any and Nothing
View kind-polymorphism.scala
scala> import scala.language.higherKinds
import scala.language.higherKinds
scala> def f[C[_], E]: List[C[E]] = Nil
f: [C[_], E]=> List[C[E]]
scala> f[List, Int]
res0: List[List[Int]] = List()
scala> f[Any, Int]
View IntervalMapSuite.scala
// libraryDependencies += "com.rklaehn" %% "intervalset" % "0.2.0"
import java.time.Instant
import scala.collection.immutable.SortedSet
import com.rklaehn.interval.IntervalMap.{ Value, FromBool => IntervalMap }
import org.scalatest.FunSuite
import spire.algebra.Order
import spire.implicits.StringOrder
import spire.math.Interval
import spire.optional.genericEq.generic
igstan /
Last active Apr 2, 2018
Higher-Order Gang of Four
# hogof — Higher-Order Gang of Four
# data Fix s a = In{out :: s a (Fix s a)}
def flatten(xss):
return [
for xs in xss
for x in xs
View free.scala
import scala.concurrent.Future
import cats.~>
object FreeMonads {
sealed trait Op[A]
object Op {
final case class Get[T](name: String) extends Op[T]

Typeclasses In Scala

Here's a common object-oriented problem in OO languages such as Java. You're using two libraries. One of them provides a class, say Foo, which performs some useful tasks. The other library provides a useful bar method that takes as an argument instances of Barable, an interface. You've got no control on either of the two libraries, but you'd like to be able to pass an instance of Foo to the bar method. Let's image it would save you a lot of work to do this. However you can't. Foo doesn't implement Barable and you can't modify Foo to have it implement the aforementioned interface. The normal solution

View factorial.eve
# Factorial in Eve
## Base Case
r = [#factorial n: 0]
r.return := 1
## Recursive Case
View patterns.swift
indirect enum Type: CustomStringConvertible {
case Int
case Fun(Type, Type)
var isFun: Bool {
switch self {
case .Fun: return true
case _: return false
View set.sml
signature TAGGED_ORD =
type t
type a
val wrap : int -> t
val compare : t * t -> order
val asRecord : { wrap : a -> t, compare : t * t -> order }
View mixin.sml
functor Member(Flag : sig type t end) =
(* Define types and values common to both MemberA and MemberB. *)
* 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 =