Scala, Java, Unix, MacOS tutorials (page 128)

This page contains a large collection of examples of how to use the methods on the Scala List class.

Scala List class introduction

The List class is an immutable, linear, linked-list class. It’s very efficient when it makes sense for your algorithms to (a) prepend all new elements, (b) work with it in terms of its head and tail elements, and (c) use functional methods that traverse the list from beginning to end, such as filter, map, foldLeft, reduceLeft.

Summary: This page contains many examples of how to use the methods on the Scala Seq class, including map, filter, foldLeft, reduceLeft, and many more.

Important note about Seq, IndexedSeq, and LinearSeq

As an important note, I use Seq in the following examples to keep things simple, but in your code you should be more precise and use IndexedSeq or LinearSeq where appropriate. As the Seq class Scaladoc states:

A farmer plowing a field in Palmer, Alaska on May 20, 2015.

At 10:30 pm.

A farmer plowing a field

I have The Dancer Upstairs playing while I work today. I don’t remember how/where/why I saw it the first time, but I remember when I saw it I thought, “That Javier Bardem guy is really good.” Other than the dog scenes, it’s a very good movie.

“Technology is our superpower. Inequality is our kryptonite.”

~ Tim O’Reilly

I’ll add that not caring about the planet we live on is also our kryptonite.

Java Design Patterns FAQ: Can you provide an example of the Factory Pattern in Java?

Sure. In this article we'll look at a small-but-complete example of the Factory Pattern ("Factory Design Pattern") implemented in Java.

[toc hidden:1]

I’m not a huge believer in certain types of karma in this world, but Jack Kornfield offers this discussion about karma related to speech, and intention:

“Speech is one area in which karma can be seen in an easy and direct way. For this exercise, resolve to take two or three days to carefully notice the intentions that motivate your speech. Direct your attention to the state of mind that precedes talking, the motivation for your comments, responses, and observations. Try to be particularly aware of whether your speech is even subtly motivated by boredom, concern, irritation, loneliness, compassion, fear, love, competitiveness, greed, or whatever state you observe ... Simply notice the various motivations in the mind and the speech that flows from them.”

“Then, after discovering which motivation is present as you speak, notice the effect of the speech. If there is competitiveness or grasping or pride or irritation behind the speech, what response does it elicit from the world around you? If there is compassion or love, what is the response? If your speech is mindless, as if you were on automatic pilot, what is the response? If there is clarity and concern, how is this received and responded to?”

It brings up an excellent point: What motivates your speech?

If you’re coming to Boulder, Colorado, the TravelBoulder.com website looks like it might be a useful resource.

I don’t know the origin of this “Do not let the behavior of others destroy your inner peace” Dalai Lama - Homer Simpson cartoon, but I like it.

Do not let the behavior of others destroy your inner peace

“Wherever you have friends, that’s your country; wherever you receive love, that’s your home.”

~ an old Tibetan saying, as read in The Book of Joy

Today’s mindfulness “lesson of the day” (mostly for myself) is a reminder to keep practicing, even when you don’t feel like it. You don’t get to choose when moments of enlightenment happen, so the best thing you can do is keep practicing so those moments will be possible when the right circumstances (karma?) come into alignment.

What happens is that over time, both the mindfulness and the enlightenment bits change the wrinkles in your brain, change your perspective and attitude, and cleanse the environmental conditioning of whatever happened to get you to this point. With continued practice you evolve (think “metamorphosis”) into a new person over time — this time a person of your own choosing, rather than a person conditioned by where and when you were born and lived.

Namaste. ;)

I just learned about Hanlon’s Razor, which states, “we should not attribute to malice that which is more easily explained by stupidity.” I have often been guilty of the malice assumption, so I found this interesting.

In a related note, Wikipedia’s definition of philosophical razors is also interesting.

If you haven’t tried it before, Scastie is an interactive playground for Scala. It also supports Dotty, which is pretty cool.

If you’re interested in metaprogramming with Scala, Scalameta is “a modern metaprogramming library for Scala that supports a wide range of language versions and execution platforms. Originally, Scalameta was founded to become a better macro system for Scala, but over time we shifted focus to developer tools and spun off the new macro system into a separate project.”

If you’re interested in the future of Scala, specifically Scala 3, the official Scala blog has an interesting article titled, Macros: The Plan for Scala 3. A beneficial part of reading at least part of the article is that you can learn a little bit about Tasty, “the high-level interchange format for Scala 3.”

Scala 3: Tasty, and the plan for macros

I just bought a bunch of MP3 music files from Amazon, and when I downloaded the zip file they provide onto my Mac, it was a bunch of files in a bunch of subdirectories; not really convenient to work with when you’re trying to import them into iTunes. So I used this Unix find command to move all of the music files from the subdirectories they were scattered in into the root directory that was created when I expanded the zip file:

cd Amazon-Music-Folder
find . -type f -exec mv {} . \;

If you ever need to either copy or move a bunch of files with a single command, I hope this example shows the correct find command syntax for your needs. (If you need to copy the files, use the cp command instead of the mv command.)

There are times when I work on images a lot with Gimp, and then there are times when I don’t work with Gimp for a month or two. When I don’t work with Gimp a lot, I tend to forget about all of the different things I can do with. Therefore, I have created this page as a “Gimp special effects cheat sheet” page to help remind me of all the cool things I can do with Gimp effects.

Under the covers — and sometimes above the covers — Scala is changing. These notes about Scala 2.13.0-M4 describe some of the changes coming to the Scala collections classes.

A few things not shown in the image are:

  • The scala-xml library is no longer bundled with the release
  • Procedure syntax (def m() { ... }) is deprecated
  • View bound syntax (A <% B) is deprecated
  • Assorted deprecated methods and classes have been removed

See the Scala 2.13.0-M4 release notes for more details.

Scala 2.13.0-M4 release notes (collections changes)