I originally wrote a long introduction to this article about Scala Options, but I decided to keep that introduction for a future second article in this series. For this article I’ll just say:
- idiomatic Scala code involves never using null values
- because you never use nulls, it’s important for you to become an expert at using
- initially you may want to use match expressions to handle
- as you become more proficient with Scala and Options, you’ll find that match expressions tend to be verbose
- becoming proficient with higher-order functions (HOFs) like
fold, and many others are the cure for that verbosity
Scala String FAQ: How can you determine whether a String contains a regular expression pattern in Scala? (Or, “How can I find the first match (or all matches) of a regex in a String?”)
Regex object by invoking the
.r method on a
String, and then use that pattern with
findFirstIn when you’re looking for one match, and
findAllIn when looking for all matches.
Perl array FAQ: How can I test to see if a Perl array already contains a given value? (Also written as, How do I search an array with the Perl grep function?)
I use the Perl grep function to see if a Perl array contains a given entry. For instance, in this Perl code:
Perl "hash key exists" FAQ: How can I test to see if a key exists in a Perl hash?
Many times when working with a Perl hash, you need to know if a certain key already exists in the hash. The Perl exists function lets you easily determine if a key already exists in the hash.
Ruby substring FAQ: I can't find a Ruby substring method, how can I tell if one Ruby string contains another string?
Solution: I expected the Ruby String class to include a method named substring, but it doesn't. My personal disappointment aside, it does have a method named include? that works the way I expected it to. Here's a simple example, using the
irbenvironment to perform a few tests.