Skip to content

Instantly share code, notes, and snippets.

git for-each-ref --sort=-committerdate --format='[%(committerdate:short)] %(committer)
%(refname:short)
%(contents)'
@dreadedsoftware
dreadedsoftware / hlistTaskDatasetJoin.scala
Last active May 5, 2017 13:43
Takes an HList of Task[Dataset] and joins them on a column producing a Task[DataFrame]
object P extends Poly1
val dummy = "_dummy_"
def join[N <: Nat, L <: HList, AsDF <: HList](
in: L, joinOn: String
)(implicit //
length: Length.Aux[L, N],
notZero: N GT nat._0,
fill: Fill.Aux[N, Task[DataFrame], AsDF],
mapper: Mapper.Aux[P.type, L, AsDF],
toList: ToList[AsDF, Task[DataFrame]],
module PatternMatch
type Type =
|Something of string * int
|Nothing
type Case =
|CaseA of a:string * b:int
|CaseB of a:string * b:double
let (|A|B|C|NOPE|) (input:char) =
match input with
//cannot do higher kinds so no type classes
//do not need higher kinds; type syntax takes care of it
//need higher kinds for useful free monad.
//no way around that?
module CategoryList
type Functor<'Type>() =
member this.map(l: list<'Type>)(f: 'Type -> 'Return) =
List.map f l
type Monad<'Type>(func: Functor<'Type>) =
member this.point(t: 'Type) = [t]
//ummm... no higher kinds... what???
type Functor<'A> =
abstract map: 'A<'B> -> ('B -> 'C) -> 'A<'C>
module Recursion
//need a keyword for recursion, otherwise boilerplate free
//very nice
let rec check many acc =
if(0 = many) then acc
else
let a = many - 1
let b = acc + many
check a b
int i = 0;
while(21 > i) printf("%d\n",i++);
while(1 < i) printf("%d\n",--i);
def roundRobin[T](seq: IndexedSeq[T]): Stream[T] = {
val size = seq.size
Stream.from(0).map{_ % size}.map{seq(_)}
}