In the following, you will learn everything you need apart from Python to write qb. For everything else, refer to the Python Documentation
Standard Library
qb comes with an extensive standard library. Here are all the different code objects that you can use
Functions
head[T](xs: T) -> T
Returns the first object of an iterator
Usage:
list = [1, 2, 3, 4, 5]
first = head(list)
cout(first)
Output:
1
tail[T](xs: T) -> T
Returns a copy of the iterator, omitting the first element
Usage:
list = [1, 2, 3, 4, 5]
without_first = tail(list)
without_first(first)
Output:
[2, 3, 4, 5]
@entrypoint(*args, **kwargs)
A unique decorator baked into the language to set the entrypoint for a program
Usage:
@entrypoint
fn main(args):
5 |> fac |> cout
fn fac(n):
if n == 0:
return 1
else:
return n * fac(n - 1)
Output:
120
Types
Some[T]
Opposite of the None
type. Represents a value of type [T]
Attributes
value
: A value of type[T]
Methods
unwrap(self) -> T
: Returns the value of theSome
object__init__(self, value: T)
: Constructor
Usage:
some = Some(5)
value = some.unwrap()
cout(value)
Output:
5
maybe
A type union that represents a value that may or may not be present
Definition
type maybe = Some | None
Usage:
fn div(a, b) -> maybe:
if b == 0:
return None
else:
return Some(a / b)
result = div(5, 0)
match result:
case Some(x):
cout(x)
case None:
cout("Division by zero")
Output:
Division by zero
either
A type union that represents a value that may be present or an error
Definition
type either = Some | Exception
Usage:
fn div(a, b) -> either:
if b == 0:
return Exception("Division by zero")
else:
return Some(a / b)
result = div(5, 0)
match result:
case Some(x):
cout(x)
case Exception(x):
cout(x)
Output:
Division by zero
collection
A lazy evaluated collection, that behaves like a list, but immutable with some neat additional methods
Attributes
*args
: The elements of the collection
Methods
for_each
: Recursively applies a function to every element of the collection and ommits the output