Simple abstraction of n-grams in Scala