That works most of the time. But sometimes, you might have and expect the value to be nil. It happens. In that case, you would confuse two separate cases, when it’s in there but it’s nil and when it’s not in there at all.

That works. It separates out the three cases. Normally you wouldn’t care, but notice that it’s really got to do the map lookup twice. It’s also got a let nested in the if. I didn’t know this for the longest time, but there’s actually a function in core that can do this in one step. Check this out.

The function that allows this is find. It looks up a key in a map, returns the map entry (key-value pair), or nil if the key is not found.

This function highlights that there are actually three cases. Sometimes we bundle the nil cases together (as in the first code example). Sometimes we bundle nil values in with non-nil values (as in the second and third code examples). Or we could treat all three cases specially. The thing is we have the choice—albeit it’s implicit and not always clear from the code.

Quarantine update 😷

I know a lot of people are going through tougher times than I am. If you, for any reason, can’t afford my courses, and you think the courses will help you, please hit reply and I will set you up. It’s a small gesture I can make, but it might help.

I don’t want to shame you or anybody that we should be using this time to work on our skills. The number one priority is your health and safety. I know I haven’t been able to work very much, let alone learn some new skill. But if learning Clojure is important to you, and you can’t afford it, just hit reply and I’ll set you up. Keeping busy can keep us sane.

Clojure Challenge 🤔

Last week’s challenge

The challenge in Issue 376 was to find the distances to the nearest vowels in a string. You can see the submissions here.

You can leave comments on these submissions in the gist itself. Please leave comments! There are lots of great discussions in there. You can also hit the Subscribe button to keep abreast of the comments. We’re all here to learn.

This week’s challenge

Sudoku Validator

Write a function that validates a finished sudoku board. It should take a vector of vectors. The inner vectors represent rows from the sudoku board. The rows should contain nine integers. If the board is well-played, the function should return true, otherwise, false.