skip to main | skip to sidebar

this.getClass()

Wednesday, September 26, 2012

Twice

 def twice1(func: Int=>Int)= (i:Int) => func(func(i));

 val add2 = (a:Int) => a + 2;
 val add4 = twice1(add2);
 
 println( add4(5));
 
 
 def twice2[T](func: T=>T)= (t:T) => func(func(t));
 
 val appendMark = (a:String) => a + "!";
 
 println( twice2(appendMark)("Hello"));
Posted by tkr at 11:52 AM
Labels: Scala

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Labels

  • Scala
  • DSL
  • AspectJ
  • Groovy
  • Java

Blog Archive

  • ▼  2012 (25)
    • ▼  September (25)
      • Structural Typing Zur Hilfe
      • Structural Food Typing
      • Pattern Matching Unpack
      • Pattern Matching Simplify
      • Pattern Matching Case Classes
      • Pattern Matching Cal
      • Pattern Matching Beverages
      • Pattern Matching Basics
      • Duck Typing
      • Case Classes
      • Closures
      • Schedule
      • Meassure Execution Time
      • Filter and Map
      • Brainteaser
      • Twice
      • Group By Task
      • Call with Retry
      • Syntactic Sugar
      • Functions, Params and Return
      • GroupBy, ForEach and Case
      • Reduce, Min, MinBy, Sum and MkString
      • Type Inference and Generics
      • Classes and Methods
      • Vals, Vars, Attributes and Contructors
  • ►  2008 (9)
    • ►  December (1)
    • ►  May (1)
    • ►  March (3)
    • ►  February (4)