koans.app

Raku Koans

Raku is an expressive language designed to make hard things easy and to be fun. It has gradual typing, grammars for parsing built in, lazy and infinite lists, junctions that test many values at once, and easy concurrency. It’s a language you can write in many styles: a quick script, carefully typed code, or something in between. These koans walk from its syntax and operators through objects, roles and functional programming, to regexes and grammars.

105 koans in 16 groups, tested with Raku’s Test module. Each is a small program whose tests fail: replace every ___ until they pass.

Start the path

Awakening

Raku's Test module, its syntax, and what counts as true.

  1. Assertions
  2. Comparing values
  3. Code that dies
  4. Organizing tests
  5. Syntax
  6. Truth

Numbers

Arithmetic, comparison, coercion, and numbers that stay exact.

  1. Arithmetic
  2. Division and divisibility
  3. Comparing numbers
  4. Increment and decrement
  5. Coercion
  6. Exact numbers
  7. Bases and infinity

Strings

Quoting, formatting, methods, and comparing text.

  1. Quoting and interpolation
  2. Heredocs and formatting
  3. String methods
  4. Splitting and transforming
  5. Comparing strings
  6. Joining and repeating
  7. Smartmatch

Variables

Sigils, types, scope, binding and dynamic variables.

  1. Scalars and sigils
  2. Types
  3. Introspection
  4. Scoping
  5. Assignment and binding
  6. Dynamic variables

Lists and hashes

Arrays, ranges, hashes and pairs, and the ways to sort, search and reduce them.

  1. Arrays
  2. Ranges
  3. Hashes
  4. Pairs
  5. Fixed-size and multidimensional arrays
  6. Functions and mutators
  7. Sorting and searching
  8. Reversed and reduction operators

Sets, subsets and enums

Collections of distinct values, types with conditions, and named constants.

  1. Sets
  2. Subsets
  3. Enums

Control flow

Conditions, loops, and the phasers that run at special moments.

  1. if
  2. unless
  3. with
  4. for
  5. given
  6. loop
  7. Loop control and phasers

Subroutines

Signatures, multiple dispatch, return values, and operators of your own.

  1. Definition
  2. Signature
  3. Multiple dispatch
  4. Default and optional parameters
  5. Slurpy and named parameters
  6. Constraints and destructuring
  7. Returning values
  8. Your own operators

Functional programming

Functions as values, chaining, feeds, hyper and meta-operators, and closures.

  1. Functions are first-class citizens
  2. Anonymous functions
  3. Chaining
  4. Feed operator
  5. Hyper operator
  6. Meta-operators
  7. Currying and composition
  8. Closures

Junctions, laziness and concurrency

Superpositions, lazy and infinite lists, and work done in parallel.

  1. Junctions
  2. Lazy lists
  3. gather and take
  4. Data parallelism
  5. Task parallelism
  6. Supplies and react
  7. Channels

Objects

Classes, attributes, constructors and methods.

  1. Classes
  2. Encapsulation
  3. Named and positional arguments
  4. Building objects
  5. Methods
  6. Private methods
  7. Class attributes and access type

Inheritance and roles

Relating classes: parents, roles, mixins and introspection.

  1. Inheritance
  2. Multiple inheritance
  3. Roles
  4. Parametric roles
  5. Mixins
  6. Introspection
  7. Testing objects

Exceptions

Catching, throwing, and defining exceptions.

  1. Catching exceptions
  2. Throwing exceptions
  3. Your own exceptions

Regular expressions

Patterns for matching, capturing and replacing text.

  1. Regex definition
  2. Matching characters
  3. Categories of characters
  4. Unicode properties
  5. Wildcards and quantifiers
  6. Captures
  7. Match results
  8. Substitution and transliteration
  9. Named regexes

Grammars

Regexes grown up: named tokens and rules combined into parsers.

  1. Tokens, rules and regexes
  2. Your first grammar
  3. The match tree
  4. Repetition and separators
  5. Actions
  6. Proto tokens
  7. Inheriting grammars

Text and the world

Unicode, the terminal, and files.

  1. Using Unicode
  2. Unicode-aware operations
  3. say and print
  4. Files
  5. Directories