Generic Quicksort

Context Mojo Reference: Sort Mojo Version: 24.2.1 Demo: Sorting a Group of People by Age This demo showcases how to sort a group of people based on their age using a versatile QuickSort algorithm. This generic QuickSort implementation can be used to sort arrays of any type, provided a custom comparison function is specified. The flexibility of this approach allows for tailored sorting criteria, making it applicable across various data structures and scenarios.

Variant keyword arguments

Context Mojo Reference: Variant Mojo Manual: Variadic keyword arguments Mojo Version: 24.2.0 Demo: Dynamic CSS Property Handler This demo showcases a flexible CSS property handler, utilizing a Variant type to accept both string literals and integers as CSS property values. The CSS function dynamically processes various CSS properties provided as keyword arguments. It distinguishes between integers and string literals, allowing for a versatile way to handle CSS properties like color, font_size, background-color, and padding, demonstrating the language’s capability for type-safe yet flexible argument handling.

Special methods for structs

Context Mojo Manual: Structs - Special Methods Mojo Version: 24.2.0 Demo: Defining a Dual Number struct This demo showcases the creation of a struct to represent Dual Numbers, which are numbers of the form a+b系, where a and b are real numbers, and 系 is a special element with the property 系 * 系 = 0 yet 系 in not 0. Addition and multiplication for dual numbers are defined as:

Dictionary of Lists

Context Mojo Reference: Dict Youtube: Overview of Dict, Variant and Optional in Mojo馃敟 Mojo Version: 24.2.0 Demo: Categorizing numbers by their sum of digits This program shows how to use a dictionary to organize numbers based on the sum of their individual digits. Within a specified numerical range, the program calculates the digit sum for each number and employs this sum as a key to group the numbers within a dictionary.

Calling Python with Keywords Arguments

Context Mojo Reference: Python Mojo Manual: Python Integration Mojo Blog: What鈥檚 new in Mojo 24.2 Mojo Version: 24.2.0 Demo: Paint a Smiley 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 from python import Python fn main() raises: var np = Python.

Dynamic types via Variants

Context Mojo Reference: Variant Youtube: Overview of Dict, Variant and Optional in Mojo馃敟 Mojo Version: 24.2.0 Demo: Summing Integers and String Representations This demo illustrates how to sum elements in an array that may be either integers or strings representing integers. It uses Mojo’s Variant to accommodate mixed data types within the same array. Notably, the data type of variable v3, whether String or Int, is determined only at runtime in this demo (dynamic type).