This file contains hidden or 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
object App{ | |
def main(args: Array[String]){ | |
println(sort(List(6,1,56,3,5,4,9))) | |
} | |
def sort(xs:List[Int]):List[Int] = { | |
def innerSort(xs: List[Int], count:Int): List[Int] = count match { | |
case 0 => xs | |
case _ => innerSort(pass(xs), count-1) |
This file contains hidden or 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
object FizzBuzzClient{ | |
def main(args: Array[String]){ | |
val fizzbuzz = for(i <- (_:Range)) yield { | |
i match { | |
case i if(i % 15 == 0) => "fizzbuzz" | |
case i if(i % 3 == 0) => "fizz" | |
case i if(i % 5 == 0) => "buzz" | |
case i if(i % 7 == 0) => "bazz" |
This file contains hidden or 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
class Node: | |
def __init__(self,val,nxt): | |
self.val = val | |
self.nxt = nxt | |
def prnt(n): | |
nxt = n.nxt | |
print n.val | |
if(nxt is not None): | |
prnt(nxt) |
This file contains hidden or 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
/** | |
* Functions that do the flattening | |
*/ | |
object Loans { | |
//def loan[T1, T2](f: (T1, T2) ⇒ Unit)(implicit f1: (T1 ⇒ Unit) ⇒ Unit, f2: (T2 ⇒ Unit) ⇒ Unit) | |
// = f1 { a ⇒ f2 { b ⇒ f(a, b) } } | |
/* | |
First round of evaluation takes 3 types |
This file contains hidden or 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 <stdio.h> | |
typedef struct Node { | |
struct Node *next; //stores the pointer to next | |
int value; | |
} Node; | |
void print_list(Node *root){ | |
while(root){ | |
printf("%d\n", root->value); |
This file contains hidden or 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
object App { | |
def main(args: Array[String]){ | |
val res = for(i <- 123 to 987 if isPanDigital(split(i)); | |
k <- 1000-i to 987 | |
if isPanDigital(split(i)++split(k)++split(i+k)))yield((i,k)) | |
println(res) | |
} | |
def isPanDigital(ls: List[Int]) = { |
This file contains hidden or 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
/* | |
Functor: | |
fmap: | |
Takes a set and changes it to another set | |
signature: | |
(f: A => B): F[A] => F[B] | |
point: | |
lifts type to functor type | |
signature: |
This file contains hidden or 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
/* | |
Invariant: | |
String is subclass of Object but in java | |
List<String> is not a subclass of List<Object> | |
Covariant | |
String in scala is a subclass of Object | |
List[String] is a subclass of List[Object] |
This file contains hidden or 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
/* | |
a by name parameter is not evaluated at the point of function application | |
but rather it is evaluated at each use within the function | |
*/ | |
object App { | |
def main (args: Array[String]){ | |
println(delayed(nano())) | |
} | |
def nano() ={ |
This file contains hidden or 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
object App { | |
def main (args: Array[String]){ | |
val fp = candidate(_) | |
val f = decorate(fp,decorator) // F o G | |
println(f("Hello World")) | |
println(fp("Hello World")) |