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
| type ICalculatingStrategy = (Int, Int)=>Int | |
| val AdderStrategy: ICalculatingStrategy = (_+_) | |
| val MultiplierStrategy: ICalculatingStrategy = (_*_) | |
| val CalculatingOperations = Map( | |
| "add" -> AdderStrategy, | |
| "multiply" -> MultiplierStrategy | |
| ) | |
| CalculatingOperations("multiply")(3, 2) |
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
| trait ICalculatingStrategy { | |
| def calculate(a: Int, b: Int): Int | |
| } | |
| object CalculatingStrategies { | |
| @inline val Add = 2 | |
| @inline val Multiply = 3 | |
| } | |
| val CalculatingOperations = Map( |
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
| interface ICalculatingStrategy{ | |
| public int calculate(int a, int b); | |
| } | |
| class CalculatingStrategyFactory{ | |
| public static ICalculatingStrategy create(String strategy){ | |
| switch(strategy) { | |
| case "add": return new ICalculatingStrategy(){ | |
| public int calculate(int a, int b) { | |
| return 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
| /* | |
| Zrada na tříděných kolekcích. Poskytnu vlastní třídění (zde podle absolutní hodnoty) a nevložím dva podle tohoto třídění ekvivalentní prvky (např. 8 a -8). Vždy tam bude jen jeden z nich. | |
| Co se divím? Pokud chci lepší prioritní frontu (PriorityQueue z nějakého důvodu nestačí) a řeším to pomocí SortedSet, kterou chci třídit podle priority. mám problém. Jakmile mám dva prvky se stejnou prioritou, zůstane jen jeden. Což je na první pohled dost neintuitivní a člověk hledá chybu někde jinde... | |
| Tuto vlastnost má evidentně TreeSet ve Scale. Má ji AFAIK i TreeSet v Javě. (Někde jsem o tom asi četl, ale samozřejmě jsem si na to nevzpomněl, když bylo potřeba...) a mohou ji mít i kolekce v jiných jazycích. Tak se nespalte. Čtěte dokumentaci. Pokud o tomto v dokumentac není zmínka, vyzkoušejte si to na jednoduchém příkladě. | |
| */ | |
| // Tady je záznam z konzole, který demonstruje tuto nepříjemnou vlastnost ve Scale. | |
| scala> collection.mutable.SortedSet[Int]()(Ordering.by(_.abs)) |
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 com.czechscala.blank | |
| trait Monoid[A]{ | |
| def op(a1: A, a2: A): A | |
| def zero: A | |
| } | |
| object IntAddition extends Monoid[Int]{ | |
| def op(a1: Int, a2: Int):Int = a1+a2 | |
| def zero: Int = 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
| #!/usr/bin/env ruby | |
| # encoding: UTF-8 | |
| require 'net/http' | |
| require 'net/https' | |
| require 'uri' | |
| ## config ## | |
| callers = { | |
| "v-sip" => "910xxxxxx", # zpětné volání na SIP (hodí se s dobrým připojením na internet) | |
| "v-phone" => "77xxxxxxx", # zpětné volání na telefon |
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
| val stream = new CSVReader(reader).readAll.toStream.tail. | |
| map{Record.importRecord}.filter(_.date.getTime >= from.getTime).filter(_.date.getTime < to.getTime) |
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
| abstract class RequestWithUser[A](request: Request[A]) extends WrappedRequest(request){ | |
| def userOption: Option[Identity] | |
| } | |
| final case class SecuredRequest[A](user: Identity, request: Request[A]) extends RequestWithUser(request){ | |
| override def userOption = Some(user) | |
| } | |
| final case class SimpleRequestWithUser[A](userOption: Option[Identity], request: Request[A]) extends RequestWithUser(request) |
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
| http_user=... | |
| http_password=... |
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
| createPlusN n x = x+n | |
| f = createPlusN 2 | |
| g = createPlusN 5 | |
| main = putStrLn $ show (f(g 6)) |