SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
Scala	
  Domain	
  Modeling	
  
and	
  Architecture	
  
Experience	
  Report	
  
                           Hossam	
  Karim	
  
for {!
      !
      locus    Chromosome ⤞ Gene ⤞ Locus!
         if Locus    range!
!
     path    locus ⤞ Sequence ⤞ nucleotide!
        if nucleotide alignment (_ > 89)!
!
} yield path!
 
inputMessage >>= fasta >>= {   	
  
        case n: Nucleotide ⇒ !
          ("media" → "nucleotide") ~> n.giNumber   	
  
                                                 	
  
        case _: AminoAcid ⇒ !
          fail[String](!
             "Expected a ‘nucleotide’ Sequence")


                                                              	
  
        case _             ⇒ !


 	
   	
  
          fail[String](!
             "Expected a ‘single’ Sequence representation”)


 	
   	
  
   } >>= {

        for {

                                               	
   	
  
           	
  
          query ← meta.Sequence ⤞ meta.nucleotide


 	
  
               if meta.nucleotide.giNumber === _
        } yield query



   } >>= xml   	
  !
 
inputMessage >>= fasta >>= {   	
  
        case n: Nucleotide ⇒ !
          ("media" → "nucleotide") ~> n.giNumber   	
  
                                                 	
  
        case _: AminoAcid ⇒ !
          fail[String](!
             "Expected a ‘nucleotide’ Sequence")


                                                              	
  
        case _             ⇒ !


 	
   	
  
          fail[String](!
             "Expected a ‘single’ Sequence representation”)


 	
   	
  
   } >>= {

        for {

                                               	
   	
  
           	
  
          query ← meta.Sequence ⤞ meta.nucleotide


 	
  
               if meta.nucleotide.giNumber === _
        } yield query



   } >>= xml   	
  !
 
inputMessage >>= fasta >>= {   	
  
        case n: Nucleotide ⇒ !
          ("media" → "nucleotide") ~> n.giNumber   	
  
                                                 	
  
        case _: AminoAcid ⇒ !
          fail[String](!
             "Expected a ‘nucleotide’ Sequence")


                                                              	
  
        case _             ⇒ !


 	
   	
  
          fail[String](!
             "Expected a ‘single’ Sequence representation”)


 	
   	
  
   } >>= {

        for {

                                               	
   	
  
           	
  
          query ← meta.Sequence ⤞ meta.nucleotide


 	
  
               if meta.nucleotide.giNumber === _
        } yield query



   } >>= xml   	
  !
 
inputMessage >>= fasta >>= {   	
  
        case n: Nucleotide ⇒ !
          ("media" → "nucleotide") ~> n.giNumber   	
  
                                                 	
  
        case _: AminoAcid ⇒ !
          fail[String](!
             "Expected a ‘nucleotide’ Sequence")


                                                              	
  
        case _             ⇒ !


 	
   	
  
          fail[String](!
             "Expected a ‘single’ Sequence representation”)


 	
   	
  
   } >>= {

        for {

                                               	
   	
  
           	
  
          query ← meta.Sequence ⤞ meta.nucleotide


 	
  
               if meta.nucleotide.giNumber === _
        } yield query



   } >>= xml   	
  !
 
inputMessage >>= fasta >>= {   	
  
        case n: Nucleotide ⇒ !
          ("media" → "nucleotide") ~> n.giNumber   	
  
                                                 	
  
        case _: AminoAcid ⇒ !
          fail[String](!
             "Expected a ‘nucleotide’ Sequence")


                                                              	
  
        case _             ⇒ !


 	
   	
  
          fail[String](!
             "Expected a ‘single’ Sequence representation”)


 	
   	
  
   } >>= {

        for {

                                               	
   	
  
           	
  
          query ← meta.Sequence ⤞ meta.nucleotide


 	
  
               if meta.nucleotide.giNumber === _
        } yield query



   } >>= xml   	
  !
trait Message[A, H] {	
  
       val body: Validation[H, Option[A]]	
  
       val headers: H	
  
 }	
  
 	
  
 	
  
   trait MessageBuilder {	
  
         def build[A, H: Monoid](	
  
             body: Validation[H, Option[A]],    	
  
             headers: H): Message[A, H]	
  
   }	
  
trait Message[A, H] {	
  
       val body: Validation[H, Option[A]]	
  
       val headers: H	
  
 }	
  
 	
  
 	
  
   trait MessageBuilder {	
  
         def build[A, H: Monoid](	
  
             body: Validation[H, Option[A]],    	
  
             headers: H): Message[A, H]	
  
   }	
  
implicit def m2m[H]!
           (implicit builder: MessageBuilder, !
            monoid: Monoid[H]) =!
	
  
new Monad[({type λ[α] = Message[α, H]})#λ] {	
  
     	
  
     def pure[A](a: => A): Message[A, H] = . . .!
	
  
     def bind[A, B]!
          (a: Message[A, H], !
           f: (A) => Message[B, H]): Message[B, H] = . . .	
  
}	
  
def pure[A](a: => A) = !
   builder.build[A, H](Success(Option(a)), ∅[H])	
  	
  
def bind[A, B](!



                                                       	
   	
  
   m: Message[A, H], !
   f: (A) => Message[B, H]): Message[B, H] = {!
	
  
       val mb: Message[B, H] = m.body match {
              case Success(Some(value))   ⇒ f(value)


                                                                   	
  
              case Success(None)          ⇒!
                  builder.build[B, H](!
                      Success(Option.empty[B]), ∅[H])



                                                	
  
              case Failure(a)           ⇒!
                  builder.build[B, H](!
                      Failure(a), ∅[H] |+| a)



       	
                                                                 	
  
       }!
	
  
       builder.build[B, H](mb.body, m.headers |+| mb.headers)
}
implicit object BasicMessageBuilder extends MessageBuilder {         	
  
     def build[A, H: Monoid](!
       body: Validation[H, Option[A]], headers: H) =   	
  
       BasicMessage(body, headers)	
  
} 	
  
!
implicit object DiagnosisMessageBuilder extends!
    MessageBuilder {	
  
    def build[A, H: Monoid](!
       body: Validation[H, Option[A]], headers: H) =   	
  
       DiagnosisMessage(body, headers)   	
  
}	
  
 	
  
def body[A](value: A)(implicit builder: MessageBuilder) :!
      Message[A, HL] =     	
  
 builder.build(Success(Some(value)), List.empty[Header])      	
  
  	
  
    	
  
import Basic._!
//import Diagnosis._!
//import Transactional._!
!
         	
  
gene map {
  for (!
       e ← meta.Chromosome ⤞ meta.Gene !
            if meta.Gene.uuid === _.uuid!
  ) yield e     	
  
} >>= search           	
  
(genex <**> geney) (_ ++ _) >>=	
  
         header("media-type", "application/vnd.x.gene+json") >>= 	
  
           json	
  
 	
  
 	
  
for {	
  
       m        ← body(<gene xmlns="urn:model:gene:1.0">...</gene>)	
  
       gene ← xml(m)	
  
 } yield gene	
  
 	
  
 	
  
gene map {	
  
      for {	
  
          e ← meta.Gene ⤞ meta.Gene.uuid 	
  
                 if meta.Gene.uuid === _.uuid	
  
      } yield e	
  
} >>= search	
  	
  
import scalaz._!
import Scalaz._!
// profit!!
trait Resource {!
      val name: String!
} !
 	
  
trait Ontology extends Resource {!
      val nestingOntology: Option[Ontology]!
      val nestedOntology: List[Ontology]!
      val ownedType: List[Type]!
      val ownedRelation: List[Relation]!
}!
	
  
trait GraphResource {	
  
       this: Resource =>	
  
 }	
  
 	
  
 trait GraphVertex extends GraphResource {	
  
       this: Entity =>	
  
       val graphFeatures: List[PrimitiveFeature]	
  
       val master: Boolean	
  
       val rootToMasterEdge: GraphEdge with Relation	
  
       val masterToSelf: Option[GraphEdge with Relation] = None	
  
 }	
  
 	
  
 trait GraphEdge extends GraphResource {	
  
           this: Relation =>	
  
 }	
  	
  
trait RelationalResource {	
  
       this: Resource =>	
  
 }	
  
 	
  
 trait NamedRelationalResource          extends RelationalResource {	
  
       this: Resource =>	
  
       val relationalName: String	
  
 }	
  
 	
  
 	
  
 trait RelationalEntity extends NamedRelationalResource {	
  
       this: Entity =>	
  
 }	
  
 	
  
 trait RelationalCompositeFeature extends RelationalResource {	
  
       this: CompositeFeature =>	
  
       val mapping: Map[String, String]	
  
 }	
  
object Chromosome extends	
  
                        Entity	
  
                   with RelationalEntity!
           	
  	
  with GraphVertex	
  
                   with XmlElement {	
  
           self =>	
  
 	
  
           sealed trait ChromosomePart {	
  
                    val ownerType = self	
  
           }	
  
 	
  
           // Ontology Trait	
  
           val featuringType = self	
  
           val ownedFeature = chromatine :: Nil	
  
 	
  
           // XML Trait	
  
           val namespace = "urn:domain:chromosome:1.0"	
  
           val prefix = "chr"	
  
 	
  
           // Features	
  
           val chromatine =	
  
                    new Chromatine(	
  
                      name = "chromatine",	
  
                      ownerType = Chromosome,	
  
                      mapping = Map.empty[String, String]) 	
  
 }	
  	
  
implicit def enrich[A <: DomainModel](model: A) = new {	
  
      def metamodel: Option[Type] = Ontology.typeOf(model)	
  
}	
  
 	
  
def xmlFilter[A <: DomainModel] =	
  
      (model: A) ⇒ model.metamodel match {	
  
        case Some(_: XmlElement) ⇒ body(XmlModel[A](model))	
  
        case _ ⇒ fail[XmlModel[A]]!
          ("No XmlElement meta-model definition could be found")	
  
}	
  
 	
  
def ingoingEdges[A <: DomainModel] =	
  
      (model: A) ⇒ model.metamodel match {	
  
        case Some(vertex: GraphVertex) ⇒ !
             Ontology.edges.filter(_.target == vertex)	
  
        case _ ⇒ List.empty[GraphEdge]	
  
}	
  
implicit def enrich[A <: DomainModel](model: A) = new {	
  
      def metamodel: Option[Type] = Ontology.typeOf(model)	
  
}	
  
 	
  
def xmlFilter[A <: DomainModel] =	
  
      (model: A) ⇒ model.metamodel match {	
  
        case Some(_: XmlElement) ⇒ body(XmlModel[A](model))	
  
        case _ ⇒ fail[XmlModel[A]]!
          ("No XmlElement meta-model definition could be found")	
  
}	
  
 	
  
def ingoingEdges[A <: DomainModel] =	
  
      (model: A) ⇒ model.metamodel match {	
  
        case Some(vertex: GraphVertex) ⇒ !
             Ontology.edges.filter(_.target == vertex)	
  
        case _ ⇒ List.empty[GraphEdge]	
  
}	
  
trait Type extends Resource 	
  
       trait SimpleType extends Type	
  
       trait Entity extends Type!
!
       trait Relation extends Type 	
  
	
  
       trait   Feature[+T <: Type] extends Resource 	
  
       trait   SimpleFeature[+T <: SimpleType] extends Feature[T] 	
  
       trait   PrimitiveFeature extends SimpleFeature[Primitive] 	
  
       trait   EnumerationFeature extends SimpleFeature[Enumeration] 	
  
       trait   CompositeFeature extends SimpleFeature[Composite]	
  
       	
  
       trait   Primitive extends SimpleType 	
  
       trait   Enumeration extends SimpleType 	
  
       trait   Composite extends SimpleType	
  
       	
  
       	
  
trait PrimitiveLogic {	
  
       	
  
                               val resource: Primitive 	
  
	
  	
  	
   def ===[A](value: Primitive[A]): Operator = . . .	
  
           	
  	
  	
  	
  	
  	
  def in[A](values: PrimitiveList[A]): Operator = . . .	
  
}	
  	
  
	
  
	
  
def find(operator: Operator): Option[T]	
  
def list(operator: Operator): List[T]!
	
  
 	
  
import PrimitiveLogic._	
  
       	
  
dao list (Locus.locusUUID in list)	
  
 	
  
dao find (Locus.locusUUID === uuid)	
  	
  
import Logic._	
  
val validation =	
  
  Sequence.nucleotide.accession.accessionNumber !== x	
  
	
  
import GraphOps._	
  
val path =	
  
  Sequence.nucleotide ⤞	
  
       Sequence.protein ⤞	
  
               Locus.typeOfGene where (_ !== y)	
  	
  
for {!
      !
      locus    Chromosome ⤞ Gene ⤞ Locus!
         if Locus    range!
!
     path    locus ⤞ Sequence ⤞ nucleotide!
        if nucleotide alignment (_ > 89)!
!
} yield path!
trait Qvt[PIM, Query, View, PSM] {	
  
 	
  
         def query(pim: PIM): List[Query]	
  
 	
  
         def view(query: Query): View	
  
 	
  
         def transform(view: View): PSM	
  
         	
  
 }	
  
class GraphSimpleQvt(	
  
     ontologyProfile: OntologyProfile, 	
  
     graphProfile: GraphProfile)	
  
   extends SimpleQvt[Model, Package, GraphOntology] {	
  
          	
  
                 def query(pim: Model) = {	
  
                       walk[Package](pim)(_.getNestedPackages).	
  
                         filter(graphProfile.graphPredicate)	
  
                 }	
  
   	
  
                 def transform(view: Package) = graph(view)	
  
   	
  
                 def graph(element: Package): GraphOntology = {	
  
                       ...	
  
                 }	
  
                 .	
  
                 .	
  
                 .	
  
}	
  
def walk[A]	
  
      (element: A)	
  
      (f: A => Iterable[A]): List[A] = {	
  
        val children = f(element).toList	
  
        children ++ !
          (children.flatMap(walk(_, f)))	
  
}	
  
def packageName(element: Package): String =	
  
     Stream!
      .iterate(element)(_.getNestingPackage)	
  
      .takeWhile(!_.isInstanceOf[Model])	
  
      .map(_.getName)	
  
      .reverse	
  
      .mkString(".") //.scala rocks !!	
  
Thank	
  You	
  

Contenu connexe

Tendances

Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...CloudxLab
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Sanjeev_Knoldus
 
Types and Immutability: why you should care
Types and Immutability: why you should careTypes and Immutability: why you should care
Types and Immutability: why you should careJean Carlo Emer
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210Mahmoud Samir Fayed
 
Lecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteLecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteDirkjan Bussink
 
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...scalaconfjp
 
The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 40 of 212
The Ring programming language version 1.10 book - Part 40 of 212The Ring programming language version 1.10 book - Part 40 of 212
The Ring programming language version 1.10 book - Part 40 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180Mahmoud Samir Fayed
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2H K
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsIván López Martín
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 35 of 189
The Ring programming language version 1.6 book - Part 35 of 189The Ring programming language version 1.6 book - Part 35 of 189
The Ring programming language version 1.6 book - Part 35 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212Mahmoud Samir Fayed
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kirill Rozov
 

Tendances (20)

Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
 
Types and Immutability: why you should care
Types and Immutability: why you should careTypes and Immutability: why you should care
Types and Immutability: why you should care
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
 
Lecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteLecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of Twente
 
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
 
The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196
 
The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88
 
The Ring programming language version 1.10 book - Part 40 of 212
The Ring programming language version 1.10 book - Part 40 of 212The Ring programming language version 1.10 book - Part 40 of 212
The Ring programming language version 1.10 book - Part 40 of 212
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy Annotations
 
Scala best practices
Scala best practicesScala best practices
Scala best practices
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84
 
The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210
 
The Ring programming language version 1.6 book - Part 35 of 189
The Ring programming language version 1.6 book - Part 35 of 189The Ring programming language version 1.6 book - Part 35 of 189
The Ring programming language version 1.6 book - Part 35 of 189
 
The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 

Similaire à Scala Domain Modeling and Architecture

An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testingVincent Pradeilles
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class PatternsJohn De Goes
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...adrianoalmeida7
 
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...Eelco Visser
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in HaskellHiromi Ishii
 
Programming haskell chapter10
Programming haskell chapter10Programming haskell chapter10
Programming haskell chapter10Kousuke Ruichi
 
QuickCheck - Software Testing
QuickCheck - Software TestingQuickCheck - Software Testing
QuickCheck - Software TestingJavran
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEBHoward Lewis Ship
 
Good functional programming is good programming
Good functional programming is good programmingGood functional programming is good programming
Good functional programming is good programmingkenbot
 
JavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher ChedeauJavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher ChedeauReact London 2017
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 

Similaire à Scala Domain Modeling and Architecture (20)

ddd+scala
ddd+scaladdd+scala
ddd+scala
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
 
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala taxonomy
Scala taxonomyScala taxonomy
Scala taxonomy
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Pattern Matching in Scala
Pattern Matching in ScalaPattern Matching in Scala
Pattern Matching in Scala
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in Haskell
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Programming haskell chapter10
Programming haskell chapter10Programming haskell chapter10
Programming haskell chapter10
 
Spock and Geb
Spock and GebSpock and Geb
Spock and Geb
 
QuickCheck - Software Testing
QuickCheck - Software TestingQuickCheck - Software Testing
QuickCheck - Software Testing
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
 
Good functional programming is good programming
Good functional programming is good programmingGood functional programming is good programming
Good functional programming is good programming
 
JavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher ChedeauJavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher Chedeau
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Scala Domain Modeling and Architecture

  • 1. Scala  Domain  Modeling   and  Architecture   Experience  Report   Hossam  Karim  
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. for {! ! locus Chromosome ⤞ Gene ⤞ Locus! if Locus range! ! path locus ⤞ Sequence ⤞ nucleotide! if nucleotide alignment (_ > 89)! ! } yield path!
  • 8.
  • 9.
  • 10.
  • 11.   inputMessage >>= fasta >>= {   case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.giNumber     case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence")   case _ ⇒ !     fail[String](! "Expected a ‘single’ Sequence representation”)     } >>= { for {       query ← meta.Sequence ⤞ meta.nucleotide   if meta.nucleotide.giNumber === _ } yield query } >>= xml  !
  • 12.   inputMessage >>= fasta >>= {   case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.giNumber     case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence")   case _ ⇒ !     fail[String](! "Expected a ‘single’ Sequence representation”)     } >>= { for {       query ← meta.Sequence ⤞ meta.nucleotide   if meta.nucleotide.giNumber === _ } yield query } >>= xml  !
  • 13.   inputMessage >>= fasta >>= {   case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.giNumber     case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence")   case _ ⇒ !     fail[String](! "Expected a ‘single’ Sequence representation”)     } >>= { for {       query ← meta.Sequence ⤞ meta.nucleotide   if meta.nucleotide.giNumber === _ } yield query } >>= xml  !
  • 14.   inputMessage >>= fasta >>= {   case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.giNumber     case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence")   case _ ⇒ !     fail[String](! "Expected a ‘single’ Sequence representation”)     } >>= { for {       query ← meta.Sequence ⤞ meta.nucleotide   if meta.nucleotide.giNumber === _ } yield query } >>= xml  !
  • 15.   inputMessage >>= fasta >>= {   case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.giNumber     case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence")   case _ ⇒ !     fail[String](! "Expected a ‘single’ Sequence representation”)     } >>= { for {       query ← meta.Sequence ⤞ meta.nucleotide   if meta.nucleotide.giNumber === _ } yield query } >>= xml  !
  • 16. trait Message[A, H] {   val body: Validation[H, Option[A]]   val headers: H   }         trait MessageBuilder {   def build[A, H: Monoid](   body: Validation[H, Option[A]],   headers: H): Message[A, H]   }  
  • 17. trait Message[A, H] {   val body: Validation[H, Option[A]]   val headers: H   }         trait MessageBuilder {   def build[A, H: Monoid](   body: Validation[H, Option[A]],   headers: H): Message[A, H]   }  
  • 18. implicit def m2m[H]! (implicit builder: MessageBuilder, ! monoid: Monoid[H]) =!   new Monad[({type λ[α] = Message[α, H]})#λ] {     def pure[A](a: => A): Message[A, H] = . . .!   def bind[A, B]! (a: Message[A, H], ! f: (A) => Message[B, H]): Message[B, H] = . . .   }  
  • 19. def pure[A](a: => A) = ! builder.build[A, H](Success(Option(a)), ∅[H])    
  • 20. def bind[A, B](!     m: Message[A, H], ! f: (A) => Message[B, H]): Message[B, H] = {!   val mb: Message[B, H] = m.body match { case Success(Some(value)) ⇒ f(value)   case Success(None) ⇒! builder.build[B, H](! Success(Option.empty[B]), ∅[H])   case Failure(a) ⇒! builder.build[B, H](! Failure(a), ∅[H] |+| a)     }!   builder.build[B, H](mb.body, m.headers |+| mb.headers) }
  • 21. implicit object BasicMessageBuilder extends MessageBuilder {   def build[A, H: Monoid](! body: Validation[H, Option[A]], headers: H) =   BasicMessage(body, headers)   }   ! implicit object DiagnosisMessageBuilder extends! MessageBuilder {   def build[A, H: Monoid](! body: Validation[H, Option[A]], headers: H) =   DiagnosisMessage(body, headers)   }       def body[A](value: A)(implicit builder: MessageBuilder) :! Message[A, HL] =   builder.build(Success(Some(value)), List.empty[Header])      
  • 22. import Basic._! //import Diagnosis._! //import Transactional._! !   gene map { for (! e ← meta.Chromosome ⤞ meta.Gene ! if meta.Gene.uuid === _.uuid! ) yield e   } >>= search  
  • 23. (genex <**> geney) (_ ++ _) >>=   header("media-type", "application/vnd.x.gene+json") >>=   json           for {   m ← body(<gene xmlns="urn:model:gene:1.0">...</gene>)   gene ← xml(m)   } yield gene           gene map {   for {   e ← meta.Gene ⤞ meta.Gene.uuid   if meta.Gene.uuid === _.uuid   } yield e   } >>= search    
  • 25.
  • 26.
  • 27.
  • 28. trait Resource {! val name: String! } !     trait Ontology extends Resource {! val nestingOntology: Option[Ontology]! val nestedOntology: List[Ontology]! val ownedType: List[Type]! val ownedRelation: List[Relation]! }!  
  • 29. trait GraphResource {   this: Resource =>   }     trait GraphVertex extends GraphResource {   this: Entity =>   val graphFeatures: List[PrimitiveFeature]   val master: Boolean   val rootToMasterEdge: GraphEdge with Relation   val masterToSelf: Option[GraphEdge with Relation] = None   }     trait GraphEdge extends GraphResource {   this: Relation =>   }    
  • 30. trait RelationalResource {   this: Resource =>   }     trait NamedRelationalResource extends RelationalResource {   this: Resource =>   val relationalName: String   }       trait RelationalEntity extends NamedRelationalResource {   this: Entity =>   }     trait RelationalCompositeFeature extends RelationalResource {   this: CompositeFeature =>   val mapping: Map[String, String]   }  
  • 31. object Chromosome extends   Entity   with RelationalEntity!    with GraphVertex   with XmlElement {   self =>     sealed trait ChromosomePart {   val ownerType = self   }     // Ontology Trait   val featuringType = self   val ownedFeature = chromatine :: Nil     // XML Trait   val namespace = "urn:domain:chromosome:1.0"   val prefix = "chr"     // Features   val chromatine =   new Chromatine(   name = "chromatine",   ownerType = Chromosome,   mapping = Map.empty[String, String])   }    
  • 32. implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.typeOf(model)   }     def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.metamodel match {   case Some(_: XmlElement) ⇒ body(XmlModel[A](model))   case _ ⇒ fail[XmlModel[A]]! ("No XmlElement meta-model definition could be found")   }     def ingoingEdges[A <: DomainModel] =   (model: A) ⇒ model.metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.edges.filter(_.target == vertex)   case _ ⇒ List.empty[GraphEdge]   }  
  • 33. implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.typeOf(model)   }     def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.metamodel match {   case Some(_: XmlElement) ⇒ body(XmlModel[A](model))   case _ ⇒ fail[XmlModel[A]]! ("No XmlElement meta-model definition could be found")   }     def ingoingEdges[A <: DomainModel] =   (model: A) ⇒ model.metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.edges.filter(_.target == vertex)   case _ ⇒ List.empty[GraphEdge]   }  
  • 34. trait Type extends Resource   trait SimpleType extends Type   trait Entity extends Type! ! trait Relation extends Type     trait Feature[+T <: Type] extends Resource   trait SimpleFeature[+T <: SimpleType] extends Feature[T]   trait PrimitiveFeature extends SimpleFeature[Primitive]   trait EnumerationFeature extends SimpleFeature[Enumeration]   trait CompositeFeature extends SimpleFeature[Composite]     trait Primitive extends SimpleType   trait Enumeration extends SimpleType   trait Composite extends SimpleType      
  • 35. trait PrimitiveLogic {     val resource: Primitive         def ===[A](value: Primitive[A]): Operator = . . .              def in[A](values: PrimitiveList[A]): Operator = . . .   }         def find(operator: Operator): Option[T]   def list(operator: Operator): List[T]!       import PrimitiveLogic._     dao list (Locus.locusUUID in list)       dao find (Locus.locusUUID === uuid)    
  • 36. import Logic._   val validation =   Sequence.nucleotide.accession.accessionNumber !== x     import GraphOps._   val path =   Sequence.nucleotide ⤞   Sequence.protein ⤞   Locus.typeOfGene where (_ !== y)    
  • 37. for {! ! locus Chromosome ⤞ Gene ⤞ Locus! if Locus range! ! path locus ⤞ Sequence ⤞ nucleotide! if nucleotide alignment (_ > 89)! ! } yield path!
  • 38.
  • 39. trait Qvt[PIM, Query, View, PSM] {     def query(pim: PIM): List[Query]     def view(query: Query): View     def transform(view: View): PSM     }  
  • 40. class GraphSimpleQvt(   ontologyProfile: OntologyProfile,   graphProfile: GraphProfile)   extends SimpleQvt[Model, Package, GraphOntology] {     def query(pim: Model) = {   walk[Package](pim)(_.getNestedPackages).   filter(graphProfile.graphPredicate)   }     def transform(view: Package) = graph(view)     def graph(element: Package): GraphOntology = {   ...   }   .   .   .   }  
  • 41. def walk[A]   (element: A)   (f: A => Iterable[A]): List[A] = {   val children = f(element).toList   children ++ ! (children.flatMap(walk(_, f)))   }  
  • 42. def packageName(element: Package): String =   Stream! .iterate(element)(_.getNestingPackage)   .takeWhile(!_.isInstanceOf[Model])   .map(_.getName)   .reverse   .mkString(".") //.scala rocks !!  
  • 43.