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
def foldLeft[T](l: List[T], initial: T, f: (T,T) => T) : T = { | |
def loop(v: List[T], accum: T) : T = { | |
l match{ | |
case Empty => accum | |
case Cons(head,tail) => loop(tail, f(head,accum)) | |
} | |
} | |
loop(l,initial) |
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 examples.monads | |
case class User(id: Int, username: String, name: String) | |
trait UserRepository{ | |
def getById(id: Int) : Option[User] | |
def save(user: Option[User]) : Unit | |
} | |
trait UserService{ |
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
import scala.annotation.tailrec | |
object Main extends App { | |
def QuickFindExample() { | |
var qu = QuickFind(10) | |
qu.union(1, 6) | |
qu.union(2, 6) | |
qu.union(2, 7) |
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 <iostream> | |
#include <memory> | |
template<class T> | |
class LessThan{ | |
public: | |
inline static bool apply(T const& a, T const& b){ | |
return a < b; | |
} | |
}; |
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 <iostream> | |
#include <functional> | |
#include <algorithm> | |
#include <exception> | |
#include <stdexcept> | |
template<class T, class Less, class Greater> | |
class Node{ | |
public: | |
explicit Node(Less const& comparer, Greater const& greater); |
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 <iostream> | |
#include <vector> | |
#include <memory> | |
#include <algorithm> | |
class drawable_concept{ | |
public: | |
drawable_concept() = default; | |
virtual ~drawable_concept() = default; | |
drawable_concept(drawable_concept const&) = delete; |
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
#ifndef DRAWING | |
#define DRAWING | |
#include <memory> | |
#include <iostream> | |
namespace concepts{ | |
namespace drawing{ | |
struct concept_t{ | |
concept_t() = default; |
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 <iostream> | |
#include <memory> | |
template<class T> | |
class Option{ | |
public: | |
Option() : value_(nullptr){ | |
} | |
Option(T const& value) : value_(std::move(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
seperateAt :: Int -> [a] -> ([a],[a]) | |
seperateAt 0 [] = ([], []) | |
seperateAt 0 xs = ([], xs) | |
seperateAt n (x: []) = (x : [], []) | |
seperateAt n (x:xs) = | |
let result = (seperateAt (n - 1) xs) | |
in (x : fst result, snd result) |
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
module Main where | |
appendSwapped :: [(a,a)] -> [(a,a)] | |
appendSwapped [] = [] | |
appendSwapped xs = xs ++ (flipped xs) | |
where flipped li = foldr (\c d -> swaptuple c : d ) [] li | |
swaptuple (a,b) = (b,a) | |
main :: IO () | |
main = print $ appendSwapped [(1,2), (3,4)] |