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.
Awakening
Raku's Test module, its syntax, and what counts as true.
Numbers
Arithmetic, comparison, coercion, and numbers that stay exact.
- Arithmetic
- Division and divisibility
- Comparing numbers
- Increment and decrement
- Coercion
- Exact numbers
- Bases and infinity
Strings
Quoting, formatting, methods, and comparing text.
- Quoting and interpolation
- Heredocs and formatting
- String methods
- Splitting and transforming
- Comparing strings
- Joining and repeating
- Smartmatch
Variables
Sigils, types, scope, binding and dynamic variables.
Lists and hashes
Arrays, ranges, hashes and pairs, and the ways to sort, search and reduce them.
- Arrays
- Ranges
- Hashes
- Pairs
- Fixed-size and multidimensional arrays
- Functions and mutators
- Sorting and searching
- Reversed and reduction operators
Sets, subsets and enums
Collections of distinct values, types with conditions, and named constants.
Control flow
Conditions, loops, and the phasers that run at special moments.
Subroutines
Signatures, multiple dispatch, return values, and operators of your own.
- Definition
- Signature
- Multiple dispatch
- Default and optional parameters
- Slurpy and named parameters
- Constraints and destructuring
- Returning values
- Your own operators
Functional programming
Functions as values, chaining, feeds, hyper and meta-operators, and closures.
- Functions are first-class citizens
- Anonymous functions
- Chaining
- Feed operator
- Hyper operator
- Meta-operators
- Currying and composition
- Closures
Junctions, laziness and concurrency
Superpositions, lazy and infinite lists, and work done in parallel.
Objects
Classes, attributes, constructors and methods.
- Classes
- Encapsulation
- Named and positional arguments
- Building objects
- Methods
- Private methods
- Class attributes and access type
Inheritance and roles
Relating classes: parents, roles, mixins and introspection.
Exceptions
Catching, throwing, and defining exceptions.
Regular expressions
Patterns for matching, capturing and replacing text.
- Regex definition
- Matching characters
- Categories of characters
- Unicode properties
- Wildcards and quantifiers
- Captures
- Match results
- Substitution and transliteration
- Named regexes
Grammars
Regexes grown up: named tokens and rules combined into parsers.
- Tokens, rules and regexes
- Your first grammar
- The match tree
- Repetition and separators
- Actions
- Proto tokens
- Inheriting grammars
Text and the world
Unicode, the terminal, and files.