Core DataOption
Blorp by Example

Option

Option makes absence explicit with Some(value) or None.

Some

Some(value) carries a present value.

some.brp
value: Option[Int] = Some(42)

None

None means no value is present.

none.brp
missing: Option[String] = None

No Null

Blorp uses Option instead of null references.

option.brp
name: Option[String] = input("name> ")

Match

match forces both Some and None paths to be considered.

match-option.brp
match maybe_name:
    Some(name): print(name)
    None: print("no name")

Get_or

get_or(default) turns an Option[T] into a T.

get-or.brp
name: String = maybe_name.get_or("guest")

Map

map transforms the value only when it is Some.

map.brp
doubled: List[Int] = values.map(pure func(x): x * 2)

And_then

and_then chains a function that also returns Option.

and-then.brp
first_name: Option[String] = user.and_then(pure func(u): u.name)

Example

name-input.brp
func main(args: List[String]) -> Int:
	match input("name> "):
		Some(name):
			print("Hello, " + name.trim())
			0
		None:
			print("Goodbye")
			0

Try It

terminal
blorp run name-input.brp