Skip to content

Instantly share code, notes, and snippets.

View sujithjay's full-sized avatar
🥑

Sujith Jay Nair sujithjay

🥑
View GitHub Profile
/**
* A tiny class that extends a list with four combinatorial operations:
* ''combinations'', ''subsets'', ''permutations'', ''variations''.
*
* You can find all the ideas behind this code at blog-post:
*
* http://vkostyukov.ru/posts/combinatorial-algorithms-in-scala/
*
* How to use this class.
*
@sujithjay
sujithjay / ASeq.scala
Last active March 13, 2018 11:52 — forked from Mortimerp9/gist:5649109
"Cheap" implementation of an immutable.IndexedSeq backed by an Array. The output of ASeq looks like an Array according to the types, but is not mutable nor cast back to a mutable Array.
import scala.reflect.ClassTag
import scala.collection.mutable.WrappedArray
import scala.collection.mutable.ArrayLike
def ASeq[T](elt: T*)(implicit ct: ClassTag[T]): IndexedSeq[T] = {
val a = elt.toArray.clone
a.deep.asInstanceOf[IndexedSeq[T]]
}
val a = Array(1,2,3) //> a : Array[Int] = Array(1, 2, 3)