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
| sealed trait Conc[+T] { | |
| def level: Int | |
| def size: Int | |
| def left: Conc[T] = throw new NoSuchElementException("no left subtree") | |
| def right: Conc[T] = throw new NoSuchElementException("no right subtree") | |
| def <>[U >: T](that: Conc[U]): Conc[U] = { | |
| if (this == Empty) that | |
| else if (that == Empty) this | |
| else concat(this, that) |
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 week2 | |
| object Lecture6 extends App { | |
| def reduceSeg1[A](inp: Array[A], left: Int, right: Int, a0: A, f: (A, A) => A): A = { | |
| var a = a0 | |
| var i = left | |
| while (i < right) { | |
| a = f(a, inp(i)) | |
| i += 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
| package week2 | |
| import java.util.Arrays | |
| import common.ParallelConstructs._ | |
| import scala.util.Random | |
| import org.scalameter._ | |
| object ParallelMergeSortLecture extends App { |
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 net.betaengine; | |
| import java.util.stream.IntStream; | |
| public class StreamCost { | |
| private boolean isPrime(int n) { | |
| System.out.println("Checking if " + n + " is a prime."); | |
| return IntStream.range(2, n).allMatch(x -> n % x != 0); | |
| } | |
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 mytests | |
| import org.scalatest.FunSuite | |
| class MonadLawSuite extends FunSuite { | |
| // 1. Remind ourselves about associativity. | |
| test("addition is associative") { | |
| val rtl = (1 + 2) + 3 | |
| val ltr = 1 + (2 + 3) |
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 union(that: TweetSet): TweetSet = { | |
| (left union (right union that)) incl elem | |
| // If we have two trees x={{{.a.}b.}c{.d{.e.}}} and y={{{.f.}g.}h{.i{.j.}}} the number of calls to union varies dramatically according to how we order things: | |
| // | |
| // (left union (right union that)) incl elem // calls=5 | |
| // (right union (left union that)) incl elem // calls=5 | |
| // (right union (that union left)) incl elem // calls=36 | |
| // (left union (that union right)) incl elem // calls=33 | |
| // (that union (left union right)) incl elem // calls=26 | |
| // (that union (right union left)) incl elem // calls=26 |
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.example; | |
| import java.util.Arrays; | |
| import java.util.NavigableSet; | |
| import java.util.Set; | |
| import java.util.TreeSet; | |
| import org.junit.Assert; | |
| import org.junit.Test; | |
| import org.springframework.boot.ApplicationArguments; |
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
| 'use strict'; | |
| var globalFoo; | |
| function Foo(name) { | |
| this.name = name; | |
| } | |
| function captureGlobalFoo(name) { | |
| globalFoo = new Foo(name); |