SHARE
TWEET

Untitled

a guest Feb 26th, 2012 19 Never
  1. import TheFamily.{Name, parents, children, male, female}
  2. import TraversalsAndFilters.{Extractor, Flattener}
  3.  
  4. object CreatingALanguage {
  5.  
  6.   def pattern[B](pf: PartialFunction[Name,B]) =
  7.     new Extractor(pf.lift)
  8.  
  9.   val Parents = new Extractor(parents.get)
  10.   val Children = new Extractor(children.get)
  11.   val Female = pattern { case n if female contains n => n }
  12.   val GrandChildren =
  13.     pattern { case Children(Children(c)) => c }
  14.   val GrandDaughters =
  15.     pattern { case GrandChildren(Female(c)) => c }
  16.  
  17.   val Mother = pattern { case Parents(Female(p)) => p }
  18.   val Siblings = pattern {
  19.     case self @ Parents(Children(siblings)) if(siblings.size != 1)  =>
  20.       siblings - self
  21.   }
  22.   val Sisters = pattern { case Siblings(Female(s)) => s }
  23.   val Male = pattern { case n if male contains n => n }
  24.   val Brothers = pattern { case Siblings(Male(b)) => b }
  25.  
  26. }
RAW Paste Data
Top