Scala Collections Fp logo

Scala Collections Fp

Organization
cxcscmu
scala-collections-fp

Scala collections, iterators, and functional programming patterns for Python developers

Overview

Publishercxcscmu
RepositorySkillLearnBench
Skill namescala-collections-fp
Stars
91
Forks
7
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by cxcscmu on GitHub. Read the source before you install it.

Installation

Install the Scala Collections Fp AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-collections-fp
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cxcscmu/SkillLearnBench.git /tmp/SkillLearnBench
mkdir -p .claude/skills
cp -r /tmp/SkillLearnBench/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-collections-fp .claude/skills/scala-collections-fp
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Scala Collections Fp in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Scala Collections Fp on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Scala Collections Fp is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Scala Collections and Functional Programming

Collections Overview

Immutable Collections (Preferred in Scala)

PythonScalaCharacteristics
list[T]List[T]Linked list, prepend fast
list[T]Vector[T]Indexed access fast, append ok
tuple[T, ...]Seq[T] (umbrella type)Immutable sequence
set[T]Set[T]Unordered, unique elements
dict[K, V]Map[K, V]Key-value pairs
range(n)(0 until n) or RangeLazy range

Mutable Collections

scala
import scala.collection.mutable

val list = scala.collection.mutable.ListBuffer[Int]()
val set = scala.collection.mutable.Set[String]()
val map = scala.collection.mutable.Map[String, Int]()

Iteration Patterns

Python iteration

python
# List comprehension
squares = [x * x for x in range(10)]

# Generator
def gen():
    for x in range(10):
        yield x * x

# Higher-order functions
list(map(lambda x: x * x, range(10)))
list(filter(lambda x: x > 10, range(20)))

Scala equivalents

scala
// Collection methods (eager)
val squares = (0 until 10).map(x => x * x).toList

// Iterator (lazy)
def gen: Iterator[Int] = (0 until 10).iterator.map(x => x * x)

// For-comprehension (syntactic sugar)
val squares = for (x <- 0 until 10) yield x * x

// Higher-order functions
List(1, 2, 3).map(_ * 2)    // List(2, 4, 6)
List(1, 2, 3, 4).filter(_ > 2)  // List(3, 4)

Iterator Pattern

Iterators are lazy and consume memory efficiently:

Python Generator

python
def tokenize_batch(self, values: Iterable[T]) -> Iterator[Token]:
    for v in values:
        yield self.tokenize(v)

# Usage
for token in tokenizer.tokenize_batch(large_list):
    process(token)  # Lazy - doesn't compute all at once

Scala Iterator

scala
def tokenizeBatch(values: Iterable[T]): Iterator[Token] =
  values.toIterator.map(tokenize)

// Usage
tokenizer.tokenizeBatch(largeList).foreach(token => process(token))

// Or with Iterator directly
def tokenizeBatch(values: Iterator[T]): Iterator[Token] =
  values.map(tokenize)

Map and FlatMap

FlatMap is essential in Scala - combines map + flatten.

Python equivalent

python
# Map
nums = [1, 2, 3]
squared = [x * x for x in nums]  # [1, 4, 9]

# FlatMap-like behavior
lists = [[1, 2], [3, 4], [5, 6]]
flattened = [x for sublist in lists for x in sublist]  # [1,2,3,4,5,6]

# Function that returns list
def duplicate(x):
    return [x, x]

result = [y for x in nums for y in duplicate(x)]  # [1,1,2,2,3,3]

Scala equivalent

scala
// Map
val nums = List(1, 2, 3)
val squared = nums.map(x => x * x)  // List(1, 4, 9)

// FlatMap
val lists = List(List(1, 2), List(3, 4), List(5, 6))
val flattened = lists.flatMap(identity)  // List(1,2,3,4,5,6)

// Function that returns List
def duplicate(x: Int): List[Int] = List(x, x)
val result = nums.flatMap(duplicate)  // List(1,1,2,2,3,3)

Fold/Reduce

Used for aggregations (Python: reduce, sum, etc.)

Python patterns

python
# Sum/reduce
total = sum([1, 2, 3, 4])  # 10

# Reduce
from functools import reduce
product = reduce(lambda a, b: a * b, [1, 2, 3, 4])  # 24

# Manual loop
result = 0
for x in [1, 2, 3, 4]:
    result += x * 2

Scala patterns

scala
// Sum (built-in)
val total = List(1, 2, 3, 4).sum  // 10

// Fold (left fold - left to right)
val product = List(1, 2, 3, 4).fold(1)((a, b) => a * b)  // 24
val product = List(1, 2, 3, 4).foldLeft(1)(_ * _)  // 24

// Or reduce (like Python's reduce, needs non-empty)
val product = List(1, 2, 3, 4).reduce(_ * _)  // 24

// Complex aggregation
val result = List(1, 2, 3, 4).foldLeft(0)((acc, x) => acc + x * 2)  // 20

Grouping and Sorting

Python grouping

python
from itertools import groupby

data = [("a", 1), ("a", 2), ("b", 3), ("b", 4)]
grouped = {k: list(g) for k, g in groupby(data, key=lambda x: x[0])}

# Sorting
sorted_data = sorted(data, key=lambda x: x[1], reverse=True)

Scala grouping

scala
val data = List(("a", 1), ("a", 2), ("b", 3), ("b", 4))
val grouped = data.groupBy(_._1)  // Map("a" -> List(...), "b" -> List(...))

// Sorting
val sortedData = data.sortBy(_._2)(Ordering.Int.reverse)
// Or
val sortedData = data.sortWith((a, b) => a._2 > b._2)

Collecting/Pattern Matching on Collections

Scala's collect is like Python's list comprehension with filtering:

scala
val nums = List(1, 2, 3, 4, 5)

// collect with partial function
val evens = nums.collect { case x if x % 2 == 0 => x }  // List(2, 4)

// Instead of: nums.filter(_ % 2 == 0)

// With transformation
val doubled = nums.collect { case x if x > 2 => x * 2 }  // List(6, 8, 10)

Lazy Evaluation

Unlike Python, Scala collections are eager by default, but you can use Views:

scala
// Eager - creates all intermediate collections
val result = (1 to 1000000)
  .map(_ * 2)
  .filter(_ > 100)
  .take(5)  // Still computes all 1M values!

// Lazy - View delays computation until forced
val result = (1 to 1000000)
  .view
  .map(_ * 2)
  .filter(_ > 100)
  .take(5)
  .toList  // Only computes what's needed!

Key Differences from Python

  1. Scala collections are immutable by default - use scala.collection.mutable.* for mutable
  2. Methods return new collections - doesn't modify in place
  3. .toList, .toVector, .toSet - explicitly convert between types
  4. No negative indexing - use lastOption or reverse.head
  5. Range is lazy - (1 to 1000000) doesn't create a million-element list
  6. for comprehension - more powerful than Python's list comprehension

Common Patterns in Tokenizer Context

Building lists

scala
// Python
tokens = []
for word in words:
    tokens.append(Token(word, ...))

// Scala - functional
val tokens = words.map(word => Token(word, ...))

// Scala - mutable accumulation (if really needed)
val tokens = scala.collection.mutable.ListBuffer[Token]()
for (word <- words) {
  tokens += Token(word, ...)
}
val result = tokens.toList

Processing with metadata tracking

scala
// Python
result = []
for i, word in enumerate(words):
    token = Token(word, ..., metadata={"position": i})
    result.append(token)

// Scala
val result = words.zipWithIndex.map { case (word, i) =>
  Token(word, TokenType.STRING, Map("position" -> i))
}

Filtering and transforming

scala
// Python
result = []
for word in words:
    processed = process(word)
    if processed is not None:
        result.append(processed)

// Scala
val result = words.flatMap { word =>
  process(word)  // Returns Option[Token]
}.toList

Frequently asked questions

What does the Scala Collections Fp AI skill do?

Scala collections, iterators, and functional programming patterns for Python developers

Why use Scala Collections Fp on TypingMind?

Because you install it once and use it with any model. Scala Collections Fp is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Scala Collections Fp in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-collections-fp. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Scala Collections Fp?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Scala Collections Fp?

As many as you like. As long as a model supports skills, you can use Scala Collections Fp with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Scala Collections Fp AI skill free?

Yes. It is published on GitHub by cxcscmu under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇