file i-o in scala
As part of my Scala-Docker-Postgres project I wanted to do something a little more useful than the “Hello World on steroids” app I have done so far.
I thought it might be fun to make a Scrabble-style dictionary, where the user inputs any combination of characters and the application returns a list of valid English words that can be constructed from those letters.
For that, I decided to make a CSV file that I can import into Postgres containing the columns word
and canonical_word
So for a row here’s how it would look:
The idea is when a user submits any collection of characters, we just alphabetize the collection and search against a list of all alphabetized or “canonical words” and return the English equivalents.
Since Scala runs on the JVM we have access to the famous java.io
library which makes parsing the list a piece of cake.
here’s the list of words I’m using: https://github.com/dwyl/english-words/blob/master/words.txt
in WordMapper.scala
:
Back in the bash terminal:
Nice and easy. Now we have a file ready to import into Postgres.