In an object oriented language, this “unit” constructor is simply an instance constructor or a factory method.Īll this suggests that the concept of for expression is more general than just iteration over a collection, and indeed it is. ![]() Monad is a type that implements map, flatMap, withFilter methods.įrom functional point of view monads can explain a large number of types with computations, ranging from collections, to computations with state and I/O, back- tracking computations, and transactions, to name but a few.įurthermore, you can characterize every monad by map, flatMap, and withFilter, plus a “unit” ( Monoid) constructor that produces a monad from an element value. Val y = expensiveComputationNotInvolvingX If definition part doesn't depends on variables bound by some generator it is better to put it outside for expression:įor (x <- 1 to 1000 y = expensiveComputationNotInvolvingX) // BAD to put y here operator identifier: printable ASCII - instead () to avoid putting ' ' after each sentenceĬaution the definition part is computed every time new value is taken.However compiler expects that the identifier from value scope will be the companion object to appropriate identifier from type scope, if not it will make a warning: So this is possible to define to identifiers with the same name (one as a class, other as a val) and use them in the same block. ![]() Scala has two namespaces for identifiers: value scope and type scope. Here comes this tutorial - to make Scala more friendly for programmers as well as present Scala in a compact way. And the power can makes problems to people who don't know Scala enough. This statement itself says a lot about Scala. But as per my observation and as per the blogosphere world this language can fit extremely well in the Java world.Įven as per a blog the Groovy developer says "if he knows that Scala exists and is about to come then he would never had developed Groovy". ![]() Like Groovy you can use all existing java libraries, however the learning curve is little steep because of the complexity of the language. Since Scala provides concurrency in terms of "ACTORS" (yep, inherited from ERLANG) and with web development frameworks like LIFT, SCALATRA, PLAY it can be termed as a replacement of Java on the JVM in the coming years. The mixture of OOP & FP ( functional programming) and its concurrent features makes Scala an excellent bread earning language of the future.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |