This file contains 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 java.text.DecimalFormat | |
import java.util.Locale | |
import scala.collection.mutable.ListBuffer | |
import scala.xml.XML | |
import org.joda.time.DateTime | |
object Main extends App { | |
Locale.setDefault(Locale.US) |
This file contains 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 World extends App { | |
val pnt = Point(10, 10) | |
val str: String = pnt(toString) | |
val x: Int = pnt(getX) | |
val pnt2: Point = pnt(setX)(20) | |
val pnt3: Point = pnt(setXY)(20, 19) | |
println(str) | |
println(x) |
This file contains 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
fun all_except_option(str, lst) = | |
case lst of | |
[] => NONE | |
| x :: xs => | |
if same_string(str, x) | |
then SOME xs | |
else case all_except_option(str, xs) of | |
NONE => NONE | |
| SOME xs' => SOME (x :: xs') |
This file contains 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 myFold[A](seq: IndexedSeq[A])(z: A)(f: (A, A) => A): A = { | |
// Divide the sequence into to halfes and then combine the results | |
def recur(from: Int, to: Int): A = { | |
if (from > to) { | |
z | |
} else if (from == to) { | |
seq(from) | |
} else { | |
f(recur(from, from + (to - from) / 2), recur(from + (to - from) / 2 + 1, to)) | |
} |
This file contains 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
public class Main { | |
public static void main(String[] args) { | |
System.out.println(example()); | |
} | |
public static String example() { | |
try { | |
throw match(); | |
} catch (Int x) { |
This file contains 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 java.util.concurrent.ForkJoinPool; | |
import java.util.concurrent.ForkJoinTask; | |
import java.util.concurrent.RecursiveTask; | |
import java.util.concurrent.TimeUnit; | |
import java.util.function.Supplier; | |
import com.google.common.base.Stopwatch; | |
import com.google.common.util.concurrent.Uninterruptibles; | |
This file contains 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
// Тайпкласс Animal (для полноты картины добавил метод hello, иначе был бы совсем тривиальный пример) | |
// Animal полностью абстрагирован от низлежашего типа A | |
trait Animal[A] { | |
def word: String | |
def talk() { println(word) } | |
def hello(a: A): String | |
} | |
// Обертка над тайпклассом Animal, чтобы можно было писать cat.hello, а не animal.hello(cat) | |
// AnimalOps полностью дублирует методы, определённые в Animal, но также может содержать еще и дополнительные методы. |
This file contains 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
// Тайпкласс Animal (для полноты картины добавил метод hello, иначе был бы совсем тривиальный пример) | |
// Animal полностью абстрагирован от низлежашего типа A | |
trait Animal[A] { | |
def word: String | |
def talk() { println(word) } | |
def hello(a: A): String | |
} | |
// Обертка над тайпклассом Animal, чтобы можно было писать cat.hello, а не animal.hello(cat) | |
// AnimalOps полностью дублирует методы, определённые в Animal, но также может содержать еще и дополнительные методы. |
This file contains 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 scalaz.NonEmptyList | |
import scalaz.syntax.monad._ | |
import scalaz.syntax.equal._ | |
import scalaz.syntax.foldable._ | |
import scalaz.std.option._ | |
import scalaz.std.list._ | |
import scalaz.std.list.listSyntax._ | |
import scalaz.std.anyVal._ | |
import scalaz.std.string._ | |
import scalaz.effect.IO |
This file contains 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 scalaz.Applicative | |
import scalaz.syntax.enum._ | |
import scalaz.syntax.show._ | |
import scalaz.std.anyVal._ | |
import scalaz.effect.IO | |
import scalaz.effect.IO._ | |
object Main extends App { | |
def fizzBuzz(i: Int): String = if (i % 3 === 0 && i % 5 === 0) "FizzBuzz" |
OlderNewer