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 pl.japila.scalania.s99 | |
object S99_P05 { | |
def reverse[T](ts: Seq[T]): Seq[T] = { | |
reverseAsList(ts.toList) | |
} | |
def reverseAsList[T](ts: List[T]): List[T] = { | |
ts match { | |
case List() => List() |
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 katas | |
object FizzBuzz { | |
def fizzBuzz(input:Int):String = { | |
class Solution(val result:String, val filter:Int) { | |
def isSatisfied(input:Int) = { | |
input % filter == 0 || input.toString.contains(filter.toString) | |
} | |
} |
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 isPalindrome[T](ts: Seq[T]): Boolean = ts.zip(ts.reverse).map((pair) => pair._1 == pair._2).contains(false) == false | |
// def isPalindrome[T](ts: Seq[T]): Boolean = ts.reverse.eq(ts) |
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 isPalindrome[T](ts: Seq[T]): Boolean = ts.zip(ts.reverse).map((pair) => pair._1 == pair._2).contains(false) == false |
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 takeWhileRec(function: (Int) => Boolean, list:List[Int]):List[Int] = list match { | |
case Nil => Nil | |
case head :: tail => if (function(head)) head +: takeWhileRec(function,tail) else Nil | |
} | |
"takeWhile" should { | |
"work the same" in { | |
val function: (Int) => Boolean = _ < 3 | |
val list: List[Int] = List(1, 2, 3) | |
takeWhileRec(function,list) === list.takeWhile(function) |
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 drop[T](n: Int, ts: Seq[T]): Seq[T] = { | |
def dropO[T](current: Int, ts: Seq[T]): Seq[T] = ts match { | |
case Nil => Nil | |
case head +: tail => if(current==0) dropO(n-1,tail) else head +: dropO(current-1,tail) | |
} | |
dropO(n-1,ts) | |
} |
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 drop[T](n: Int, ts: Seq[T]): Seq[T] = { | |
def dropO[T](current: Int, ts: Seq[T]): Seq[T] = ts match { | |
case Nil => Nil | |
case head +: tail => if(current==0) dropO(n-1,tail) else head +: dropO(current-1,tail) | |
} | |
dropO(n-1,ts) | |
} |
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 org.junit.Test; | |
public class ThreadTest { | |
private boolean flag = true; | |
@Test | |
public void testName() throws Exception { | |
new Thread(new Runnable() { |
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
private Function<Color, Color> filter; | |
@Test | |
public void j8Test() throws Exception { | |
Optional<Integer> optional = stream().filter((a) -> a > 10).findFirst(); | |
optional. | |
Integer result = optional.map(i -> i * i).orElse(-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
private Function<Color, Color> filter; | |
@Test | |
public void j8Test() throws Exception { | |
Optional<Integer> optional = stream().filter((a) -> a > 10).findFirst(); | |
optional. | |
Integer result = optional.map(i -> i * i).orElse(-1); |
OlderNewer