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 MonadsTesting { | |
println("http://stackoverflow.com/questions/14598990/confused-with-the-for-comprehension-to-flatmap-map-transformation") | |
//> http://stackoverflow.com/questions/14598990/confused-with-the-for-comprehens | |
//| ion-to-flatmap-map-transformation | |
val some=Some ("hello") //> some : Some[String] = Some(hello) | |
some.flatMap(str=>Some(str+"x")) //> res0: Option[String] = Some(hellox) |
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
package me.rerun; | |
import java.util.Arrays; | |
public class QuickSort { | |
public static void quickSort (Comparable comparableArray[], int lowIndex, int highIndex){ | |
//at least one item must exist in the array | |
if (lowIndex>=highIndex){ |
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
package me.rerun.incubator; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.Future; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.TimeoutException; | |
import java.util.concurrent.atomic.AtomicInteger; |
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
package me.rerun.incubator; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.Future; | |
import java.util.concurrent.atomic.AtomicInteger; |
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
static final class RunnableAdapter<T> implements Callable<T> { | |
final Runnable task; | |
final T result; | |
RunnableAdapter(Runnable task, T result) { | |
this.task = task; | |
this.result = result; | |
} |
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
/** | |
* Only basic arithmetic operators are supported. However, could easily be | |
* extended to support any binary operators | |
* | |
* This program is not an infix to postfix converter. However, this program does the following | |
* | |
* 1) Evaluates a non-parenthesized infix expression and drives it to a final value | |
* 2) Does not support parentheses | |
* 3) Supports multiple digits as operands | |
* 4) Empty space allowed |
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
/** | |
* Only basic arithmetic operators are supported. However, could easily be | |
* extended to support any binary operators | |
* | |
* This program is not an infix to postfix converter. However, this program does the following | |
* | |
* 1) Evaluates a parenthesized or non-parenthesized infix expression and drives it to a final value | |
* 2) Supports parentheses | |
* 3) Supports multiple digits as operands | |
* 4) Empty space allowed |
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 static org.testng.Assert.assertFalse; | |
import static org.testng.Assert.assertTrue; | |
import java.util.Arrays; | |
import org.testng.annotations.Test; | |
public class DeepEquals { |
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
package com.sorting.merge; | |
import static com.sorting.insert.SortUtils.less; | |
public class MergeSort { | |
public Comparable[] sort(Comparable[] items) { | |
sort (items,new Comparable[items.length], 0, items.length-1); | |
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
package com.sorting.insert; | |
import static com.sorting.insert.SortUtils.*; | |
public class InsertionSort { | |
public Comparable[] sort(Comparable[] items) { | |
for (int i=0;i<items.length;i++){ | |
for (int j=i;j>0;j--){ |
OlderNewer