Scala: How to access the MongoDB document '_id' field with Casbah
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a very short recipe, Recipe 16.7, “How to access the MongoDB document 'ID' field (_id) with Casbah.”ProblemYou...
View ArticleHow to create a simple Scala object from a JSON String
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 15.3, “How to create a simple Scala object from a JSON String.”ProblemYou need to...
View ArticleHow to create JSON strings from Scala classes that have collections fields
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 15.2, “How to create a JSON String from Scala classes that have collections.”ProblemYou want to generate...
View ArticleHow to create a JSON string from a Scala object
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 15.1, “How to create a JSON string from a Scala object.”ProblemYou’re working outside of a specific...
View ArticleHow to use abstract and concrete fields in Scala traits
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a very short recipe, Recipe 8.2, “How to use abstract and concrete fields in Scala traits.”ProblemYou want to...
View ArticleHow to create static members with Scala companion objects
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 6.6, “How to create static members with Scala companion objects.”ProblemYou want to create a class that...
View ArticleScala: How to create methods that take variable-arguments (varargs) fields
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.7, “How to create methods that take variable-arguments (varargs) fields.”ProblemTo make a method more...
View ArticleHow to use parameter names when calling a Scala method
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.4, “How to use parameter names when calling a Scala method.”ProblemYou prefer a coding style where you...
View ArticleHow to set default values for Scala method parameters
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.3, “How to set default values for Scala method parameters.”ProblemYou want to set default values for...
View ArticleScala: How to define properties in an abstract base class or trait
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 4.13, “How to define properties in an abstract base class or trait.”ProblemYou want to define abstract...
View ArticleHow to set uninitialized var fields (field types) in Scala
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 4.9, “How to set uninitialize var field types in Scala.”ProblemYou want to set the type...
View ArticleHow to assign a Scala class field to a (lazy) block or function
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 4.8, “How to assign a Scala class field to a block or function.”ProblemYou want to initialize a field in...
View ArticleHow to override Scala's default numeric type when defining a field
Scala FAQ: How do I override the default numeric type that Scala assigns when I declare an Int, Long, Short, Float, or Double val or var field?SolutionIf you assign 1 to a variable, Scala assigns it...
View ArticleAndroid field/variable naming conventions
This image, copied from this android.com page, shows the suggested Android field naming conventions.
View ArticleHow to access Scala var and val fields from Java
I just ran into one thing I wish I had included in the Scala Cookbook that I didn’t include: How to access a val or var field in a Scala object from your Java code.In short, if you have a field named...
View ArticleHow to create a URL column in a Sencha ExtJS grid panel
I don’t know if this is the best way to do this, but if you want a column in a Sencha ExtJS grid to display a URL field that the user can click, I can confirm that this code works:read more
View ArticleInitialize Scala variables with Option, None, and Some (not null)
Summary: How to properly use the Scala Option/Some/None idiom to initialize empty var fields -- and specifically how not to use null values for the same purpose.When you get started in the Scala world,...
View ArticleMy latest fake oil painting - Cattle in a field, facing East, late October...
My latest fake oil painting, which I call, "Cattle in a field, facing East, on a late October afternoon, Denver skyline in the background."(Also known by the alternate title, "Things I do when I can't...
View ArticleScala best practices: null values, Option, Some, and None
In his excellent book, Beginning Scala, David Pollak provides a series of statements that can be considered as a recipe for avoiding the use of null values in your Scala code. I've organized his...
View ArticleA Scala implicit method argument and field example
UPDATE: This example shows how to create an implicit method in Scala 2.9 or older. You can use a slightly simpler approach with Scala 2.10 and newer, which I've documented in this Scala 2.10 implicit...
View Article