skip to main | skip to sidebar

this.getClass()

Thursday, September 27, 2012

Closures

def someFunc() = {
  var someLocalVariable = 0;
  val closure1 = {()=> someLocalVariable += 5; someLocalVariable; };
  val closure2 = {()=> someLocalVariable -= 2; someLocalVariable; };
  (closure1, closure2);
}

val closures = someFunc();

println(closures._1());
println(closures._1());
println(closures._2());
Posted by tkr at 6:18 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)