Skip to content

Instantly share code, notes, and snippets.

Jatin purijatin

Block or report user

Report or block purijatin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
purijatin /
Created Sep 4, 2017
Get started with CompletableFuture Session
* A Future represents the result of an asynchronous
* computation. Methods are provided to check if the computation is
* complete, to wait for its completion, and to retrieve the result of
* the computation. The result can only be retrieved using method
* {@code get} when the computation has completed, blocking if
* necessary until it is ready. Additional methods are provided to
* determine if the task completed normally or was cancelled.
View WordCount.scala
import akka.Done
import{ActorRef, ActorSystem}
import{Flow, RunnableGraph, Sink, Source}
import{ActorMaterializer, OverflowStrategy}
import scala.concurrent.Future
object Generic {

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
View TicTacToe.scala
import io.Source
import scala.util.control.Breaks._
* Scala TicTacToe game without any side effects
* Written in response to following post (which also contains task description):
object TicTacToe {
purijatin / TraversableWithStatistics.scala
Last active Mar 15, 2017 — forked from MishaelRosenthal/TraversableWithStatistics.scala
Adding mean and variance to Scala collections.
View TraversableWithStatistics.scala
object TraversableWithStatistics {
implicit class RichTraversable[A](collection: Traversable[A])(implicit val numeric : Numeric[A]) {
private def pow2[C](x: C)(implicit num: Numeric[C]) = math.pow(num.toDouble(x), 2)
private def sqrt[C](x: C)(implicit num: Numeric[C]) = math.sqrt(num.toDouble(x))
def mean = {
View JsonParse.scala
import scala.util.matching.Regex
import scala.util.parsing.combinator.RegexParsers
object JsonPrac {
def main(args: Array[String]) {
assert(JParser( """[1,2,3]""").successful)
assert(JParser( """
{"id": "ZoomIn"}
View Calculator.scala
import scala.util.parsing.combinator.RegexParsers
object Calculator extends Cal {
def main(args: Array[String]) {
assert(!parse(exp, "a").successful)
assert(parseAll(exp, "1").get == 1)
assert(parseAll(exp, "1+1").get == 2)
assert(parseAll(exp, "1*1").get == 1)
assert(parseAll(exp, "1/1").get == 1)
purijatin / ZooKeeperLock.scala
Last active Oct 3, 2016
Distributed Lock based on ZooKeeper
View ZooKeeperLock.scala
package zookeeper
import java.util.concurrent.{ExecutorService, Executors}
import org.apache.zookeeper._
import scala.collection.JavaConverters._
import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.util.control._
View DifferentTypes.scala
To write a method which takes two type parameters and both should not be the same:
trait =!=[A,B]
implicit def neq[A,B]: =!=[A,B] = null
implicit def eqAmb[A]: =!=[A,A] = null
implicit def eqAmbig2[A]: =!=[A,A] = null
case class Foo2[A,B]( a: A, b: B )( implicit ev: A =!= B )
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Optional;
import static java.util.Objects.isNull;
public class User {
You can’t perform that action at this time.