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
Functor & Fmap. | |
--------------- | |
Lets start with fmap. fmap is defined in a Functor. | |
fmap takes a function and a box. | |
fmap then extracts the content from the box, | |
applies the function on the content and puts the result back into the box. | |
The signature of the fmap is | |
> fmap :: Functor f => (a -> b) -> f a -> f b |
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
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<script type="text/javascript"> | |
var socket = new WebSocket("ws://localhost:8080/echo"); | |
socket.onopen = function () { | |
console.log("Connected"); | |
socket.send('hello, world!'); |
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
libraryDependencies ++= Seq( | |
"org.atmosphere" % "atmosphere-runtime" % "1.0.4", | |
"org.atmosphere" % "nettosphere" % "2.1.9") | |
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" | |
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" |
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 org.atmosphere.config.service.WebSocketHandlerService | |
import org.atmosphere.nettosphere.{Config, Nettosphere} | |
import org.atmosphere.websocket.{WebSocket, WebSocketHandlerAdapter} | |
object Main { | |
def main(args: Array[String]) { | |
val builder = new Config.Builder().host("127.0.0.1").port(8080) |
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
def compose[A,B,C] (f: B => C, g : A => B) : A => C = a => f(g(a)) |
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
def curry[A,B,C] (f: (A,B) => C): A => (B => C) = a => b => f(a,b) | |
curry((a:Int, b:Int) => a * b)(1)(2) | |
def uncurry [A,B,C] (f: A => B => C) : (A,B) => C = (a,b) => f(a)(b) | |
var f = uncurry (curry((a:Int, b: Int) => a * b)) // f (3,5) = 15 |
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
def isSorted[A] (items : Seq[A], ordered : (A,A) => Boolean) : Boolean = | |
(items, items.tail).zipped.forall(ordered) | |
/*items match { | |
case null => true | |
case x :: Nil => true | |
case x :: y :: xs => ordered (x, y) && isSorted (xs, ordered) | |
}*/ | |
isSorted(Seq(1,2,3), (a: Int, b: Int) => a < b); | |
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
//tail recursive fibonacci numbers | |
def fib(n: Int) = { | |
@scala.annotation.tailrec | |
def fibImpl(a:Int, nxt: Int, res: Int) : Int = | |
a match { | |
case 0 => res | |
case _ => fibImpl(a-1, nxt+res, nxt) | |
} | |
fibImpl(n, 1, 0); | |
} |
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
<html> | |
<body> | |
Welcome to clojure world! | |
<script type="text/javascript" src="js/goog/base.js"></script> | |
<script src="js/main.js" type="text/javascript"></script> | |
<script text="text/javascript"> | |
goog.require("webapp.client"); | |
</script> |
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
(ns webapp.client | |
(:require | |
[figwheel.client :as fw :include-macros true])) | |
(fw/watch-and-reload) | |
(js/alert "Hello Zumanji") | |