Skip to content

Instantly share code, notes, and snippets.

View abdheshkumar's full-sized avatar

Abdhesh Kumar abdheshkumar

View GitHub Profile
//In library
trait Event
trait EventCombiner[A <: Event] {
def initialValue: Int
def combineEvents(value: Int, e2: A): Int
}
def foldEvents[A <: Event](list: Seq[A])(implicit C: EventCombiner[A]): Int =
list.foldLeft(C.initialValue)(C.combineEvents)

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 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
@abdheshkumar
abdheshkumar / fpmax.scala
Created July 13, 2018 09:27 — forked from jdegoes/fpmax.scala
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
DDL
DDL is short name of Data Definition Language, which deals with database schemas and descriptions, of how the data should reside in the database.
CREATE – to create database and its objects like (table, index, views, store procedure, function and triggers)
ALTER – alters the structure of the existing database
DROP – delete objects from the database
TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
COMMENT – add comments to the data dictionary
RENAME – rename an object
@abdheshkumar
abdheshkumar / Conversions.scala
Created April 11, 2018 12:14 — forked from SystemFw/Conversions.scala
Typed schema conversion with shapeless
object Conversions {
import cats._, implicits._, data.ValidatedNel
import mouse._, string._, option._
import shapeless._, labelled._
private type Result[A] = ValidatedNel[ParseFailure, A]
case class ParseFailure(error: String)
trait Convert[V] {
val tryCatch = try {
//Code here that might raise an exception
throw new Exception
} catch {
case ex: Exception =>
//Code here for handle an exception
}
val tryMultipleCatch = try {
//Code here that might raise an exception
sealed trait A
case class B[Req, Res](r: Req, rs: Res) extends A
case class C[Req](r: Req, errorCode: Int, errorMessage: String) extends A
trait TypeA[Req, Res] {
def success(t: Req, r: Res): Unit
def error(t: Req): Unit
}
implicit val forString = new TypeA[String, String] {
override def success(t: String, r: String): Unit = ???
trait Item
trait PlasticItem extends Item
trait PlasticBottle extends PlasticItem
trait PaperItem extends Item
trait NewsPaper extends PaperItem
@abdheshkumar
abdheshkumar / Object-Function.js
Created October 3, 2017 09:34
Object-Function
Html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
Office = {
initialize: function (reason) {
{
type: 'devs.Model',
inPorts: [],
outPorts: [],
size: {
width: 80,
height: 80
},
attrs: {