This file contains 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 ru.lester.shapeless | |
import shapeless._ | |
import poly._, record._, syntax._, syntax.singleton._, labelled.{FieldType, field} | |
object MapOverBookGeneric { | |
case class Book(author: String, title: String, id: Int, price: Double) | |
val bookGen = LabelledGeneric[Book] |
This file contains 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 ru.lester.shapeless | |
import shapeless._ | |
object ShowGeneric { | |
trait Show[T] { | |
def show(t: T): String | |
} |
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE RankNTypes #-} | |
module Main where | |
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.State |
This file contains 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 ru.lester.scalaz7.monadlisten | |
import scalaz._, Scalaz._ | |
object MonadListenOps { | |
implicit val monadListen = EitherT.monadListen[Writer, List[String], String] | |
def validateNegative(x: Int) = if(x < 0) monadListen.left[Int]("Number is negative") else monadListen.right[Int](x) | |
def validateEmpty(str: String) = Option(str).fold(monadListen.left[String]("String is null")){s => if(s.isEmpty || s.forall(_.isWhitespace)) monadListen.left[String]("String is empty") else monadListen.right[String](s)} |
This file contains 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 ru.lester.scalaz7.free | |
import scalaz._ | |
import scalaz.effect._ | |
import Scalaz._ | |
import IO._ | |
sealed trait TeletypeF[+S] | |
case class PrintLn[+S](a: String, s: S) extends TeletypeF[S] |
This file contains 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 ~>[F[_], G[_]] { | |
def apply[T](f: F[T]): G[T] | |
} | |
object last extends (List ~> Option) { | |
def apply[T](l: List[T]): Option[T] = l match { | |
case x::Nil=> Some(x) | |
case _::xs => last(xs) | |
case _ => None | |
} |
This file contains 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
object QuickSort extends App { | |
sealed trait PivotStrategy | |
case class First() extends PivotStrategy | |
case class Last() extends PivotStrategy | |
case class Medium() extends PivotStrategy | |
//val array = Array(3, 8, 2, 5, 1, 4 ,7, 6) | |
var total = 0 |
This file contains 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
// returns map of pairs (attribute name -> list of attribute values) | |
def getAttributesMap(dn: String) : Option[Map[String, List[String]]] = { | |
val attributes: Option[Attributes] = // get javax.naming.directory.Attributes from LDAP | |
attributes.flatMap(attrs => { | |
val allAttributes = Option(attrs.getAll()); | |
allAttributes.map(allAttrs => { | |
val res = enumNamingEnumeration(allAttrs, accum, get) map (_.run) | |
res.unsafePerformIO ~> Map.empty[String, List[String]] | |
}) | |
}) |