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.concurrent.duration.Duration.Inf | |
| import scala.concurrent.{Await, Future} | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| object App{ | |
| def main(args:Array[String]):Unit = { | |
| import cats.syntax.cartesian._ | |
| import cats.instances.future._ | |
| val program = for { |
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
| object Website { | |
| import cats.free.Free | |
| import cats.Comonad | |
| import scala.io._ | |
| final case class User(username: String) | |
| sealed trait Page | |
| final case object Welcome extends Page | |
| final case object TryAgain extends Page |
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 cats.data.OptionT | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| import scala.concurrent.duration.Duration | |
| import scala.concurrent.{Await, Future} | |
| object CollectingOptionTs { | |
| def main(args: Array[String]): Unit = { | |
| import cats.instances.future._ |
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 cats.MonadError | |
| import cats.instances.either._ | |
| import cats.instances.future._ | |
| import cats.instances.try_._ | |
| import cats.syntax.applicativeError._ | |
| import cats.syntax.flatMap._ | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| import scala.concurrent.duration._ | |
| import scala.concurrent.{Await, Future} |
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.language.postfixOps | |
| import scala.concurrent.ExecutionContext | |
| import scala.concurrent.Future | |
| import cats.data.EitherT | |
| import cats.instances.list._ | |
| import cats.instances.future._ | |
| import cats.syntax.traverse._ |
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 cats.data.State | |
| import cats.data.State._ | |
| def factorialWithState(x: Int): Int = { | |
| def stateFactorial: State[Int, Int] = | |
| get.flatMap(x => | |
| if (x <= 1) | |
| State.pure(1) | |
| else { | |
| set[Int](x - 1).flatMap(_ => stateFactorial.map(z => x * z)) |
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 futureeitherapplicativestack | |
| import cats._ | |
| import cats.data._ | |
| import cats.implicits._ | |
| import scala.concurrent.{Await, Future} | |
| import scala.concurrent.duration.Duration | |
| import scala.concurrent.ExecutionContext.Implicits.global |
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 cats.data._ | |
| import cats.syntax.traverse._ | |
| import cats.std.list._ | |
| import scala.util.Try | |
| def tryInt(s: String): Try[Int] = Try(s.toInt) | |
| def reader: Reader[Try[Int], String] = Reader[Try[Int], String] { t => | |
| t.map(s => s"$s is a number").getOrElse("not") |
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
| //Problem : https://www.hackerrank.com/challenges/angry-children | |
| // Algorithm : | |
| // Read input into 2D lists => List(List(x)) | |
| // Sort every row of the matrix | |
| // Then iterate over every column, check for unsorted first column | |
| // break if we find unsorted column | |
| object Test 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
| object Solution { | |
| def main(args: Array[String]) { | |
| val sc = new java.util.Scanner (System.in); | |
| var n = sc.nextInt(); | |
| var a = Array.ofDim[Int](n,n); | |
| for(a_i <- 0 to n-1) { | |
| for(a_j <- 0 to n-1){ | |
| a(a_i)(a_j) = sc.nextInt(); | |
| } |