Skip to content

Instantly share code, notes, and snippets.

View caente's full-sized avatar

Miguel Iglesias caente

View GitHub Profile
sealed abstract case class Profile(
personId:PersonId,
timezone:DateTimeZone,
profileStatus:PersonStatus, // CUSTOMER, DISABLED, etc
schedulingHours:List[Constraint]
...
)
sealed trait Coordination
case class AssistantTo(p:Profile) extends Coordination// assistants are independent of the Meeting
package features
import shapeless._
import ops.hlist.Selector
import syntax.std.function._
import ops.function._
import simulacrum._
import scalaz._, Scalaz._
object Main {
import utils.Find
package features
import shapeless._
import ops.hlist.Selector
import syntax.std.function._
import ops.function._
import simulacrum._
import scalaz._, Scalaz._
object Main {
import utils.Find
[info] Compiling 1 Scala source to /Users/caente1/workshop/filter_field/target/scala-2.11/classes...
[info] /Users/caente1/workshop/filter_field/src/main/scala/main.scala:70: shapeless.this.Generic.materialize is not a valid implicit value for shapeless.Generic.Aux[snippet.ATrait,V] because:
[info] type parameters weren't correctly instantiated outside of the implicit tree: inferred type arguments [shapeless.:+:[snippet.A1,shapeless.:+:[snippet.A2,shapeless.CNil]],Nothing] do not conform to method materializeProduct's type parameter bounds [V <: shapeless.HList,R <: shapeless.HList]
[info] assert(FilterField[ATrait].filterField( '_id, atrait ) == 1 :: HNil)
[info] ^
[info] /Users/caente1/workshop/filter_field/src/main/scala/main.scala:70: shapeless.this.LabelledGeneric.materializeProduct is not a valid implicit value for shapeless.LabelledGeneric.Aux[snippet.ATrait,G] because:
[info] hasMatchingSymbol reported error: could not find implicit value for parameter gen: shapeless.Generic.Aux[
@caente
caente / fields.scala
Last active December 9, 2015 21:43
extracting fields from case classes
import shapeless._
import ops.{ hlist => hl, coproduct => cp }
object FlexibleTypes2 {
/*
it extracts the values of a common type from a hierarchy of case classes
*/
implicit class TaggedMonad[A, B](val t:A @@ B ) extends AnyVal {
def map[C](f: A => C ):C @@ B = Tag[C, B](f(Tag.unwrap(t)))
def flatMap[C](f : A => C @@ B): C @@ B =f(Tag.unwrap(t))
}
sealed trait A
sealed trait B
val i: Int @@ A = Tag[Int, A](1)
case class Stretch(
before: Int,
after: Int
)
case class MidnightRange(
start: Int,
end: Int
)
object typesWrapped {
case class Divided( value: Int ) extends AnyVal
case class Subtracted( value: Int ) extends AnyVal
case class Multiplied( value: Int ) extends AnyVal
def divide( i: Int ): Divided = Divided( ( i / 5 ).toInt )
def subtract( i: Divided ): Subtracted = Subtracted( i.value - 10 )
object types {
def divide(i: Int): Int = (i/5).toInt
def subtract(i: Int): Int = i - 10
def multiply(i: Int): Int = i * -1
def allOK(i: Int):Int = {
val s1 =divide(i)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dimeder</groupId>
<artifactId>llull</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>llull Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>