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
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
# 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
/** | |
* 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
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
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
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
/* | |
Assignment compatibilty has several dimensions. The object type and the | |
type of its parameters. Type parameters can be covariant the object type | |
cannot. What's the difference? Covariant parameters allow subclassing. | |
Defintions: | |
========== | |
covariant: converting from wider(Animals) to narrower(Cats) | |
contravariant: converting from narrower to wider Triangles->shapes | |
invariant: not able to convert |
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
/* | |
Article: http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/ | |
The cake pattern is a way to do dependency injection in Scala. | |
Rather than using explicit xml configuration we compose our | |
configurations using a combination of self-typ annotations, traits, | |
and companion objects. | |
self-type Annotation | |
==================== |
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
package com.art.samples.inplace_string_reverse; | |
/** | |
* Hello world! | |
* | |
*/ | |
public class App | |
{ | |
/** | |
* @param args | |
*/ |