I have a program which looks roughly like this
- Waits for some files
- When they arrive, parses them to extract data
- Reads database state
- Performs calculation
- Saves new state to database
- Generates emails on the basis of computed data
import java.util.UUID | |
import monocle.Iso | |
trait IsUUID[A]: | |
def iso: Iso[UUID, A] | |
object IsUUID: | |
def apply[A](using ev: IsUUID[A]): IsUUID[A] = ev |
import cats.implicits._ | |
import cats.{ Applicative, Monad } | |
// Операции над контекстом | |
trait ContextWriter[F[_]] { | |
def put(key: String, value: String): F[Unit] | |
} | |
package me.limansky | |
import cats.Monoid | |
import shapeless.labelled.{FieldType, field} | |
import shapeless.{::, HList, HNil, LabelledGeneric, Lazy, Witness} | |
trait MapReader[T] { | |
def read(m: Map[String, String]): T | |
} |
Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.
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
/** | |
* Solves the n-Queen puzzle in O(n!) | |
* Let p[r] be the column of the queen on the rth row (must be exactly 1 queen per row) | |
* There also must be exactly 1 queen per column and hence p must be a permuation of (0 until n) | |
* There must be n distinct (col + diag) and n distinct (col - diag) for each queen (else bishop attacks) | |
* @return returns a Iterator of solutions | |
* Each solution is an array p of length n such that p[i] is the column of the queen on the ith row | |
*/ | |
def nQueens(n: Int): Iterator[Seq[Int]] = | |
(0 until n) |
<RaceCondition> can I use Scalaz to get exhaustion checks when matching on numeric values? Scala obviously doesn't do that | |
<RaceCondition> ! 1.1 match { case x if 0.0 <= x && x < 0.5 => "bad"; case x if 0.5 <= x && x <= 1.0 => "good" } | |
<dibblego> doubt it | |
<multibot_> scala.MatchError: 1.1 (of class java.lang.Double) | |
<multibot_> ... 38 elided | |
<dibblego> use types though? | |
<RaceCondition> wdym? | |
<dibblego> use a type to note each range | |
<dibblego> you want a floating-point between 0.0 and 1.0? | |
<RaceCondition> wouldn't that just move the problem to a different stage? |
public class StructureMapConfiguration | |
{ | |
public static void Initialise(IEnumerable<Assembly> assembliesToScan, params Action<IInitializationExpression>[] extraConfigs) | |
{ | |
ObjectFactory.Initialize(config => | |
{ | |
config.Scan(scan => | |
{ | |
foreach(var assembly in assembliesToScan) | |
{ |
import Data.Maybe | |
import Control.Monad (liftM) | |
import Data.List (isPrefixOf) | |
import qualified Data.Map as M | |
import qualified Data.Foldable as F | |
-- | Trie container data type | |
data Trie a = Trie { value :: Maybe a | |
, children :: M.Map Char (Trie a) } | |
deriving (Show) |