common

One of those faces

A strange thing about being me is that many people I’ve never met think they know me. It happened with almost everyone at the Buddhist Geeks conferences — “Do I know you?” Last week it happened at Whole Foods, where a cashier talked to me like we were old friends, asking if I ever got to do so and so. I had to tell him that wasn’t me.

Due to my most recent illness I haven’t eaten at a restaurant since before October 10, 2017, but yesterday I went to a burger place to try a small burger and see if I could eat it. Right away the cashier said, “Hi! How have you been? Hey, did you cut your hair?” I guess I just have one of those faces.

How to put common code in Scala package objects

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 6.7, “How to put common code in Scala package objects.”

Problem

You want to make functions, fields, and other code available at a package level, without requiring a class or object.

Solution

Put the code you want to make available to all classes within a package in a package object.