Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core Lib Documentation: boolean module #6650

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion corelib/src/boolean.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
//! Boolean operations.
//!
//! The `bool` type is a primitive type in Cairo representing a boolean value that can be either
//! `true` or `false`. This module provides trait implementations for boolean operations.
//!
//! # Examples
//!
//! Basic boolean operations:
//!
//! ```
//!
//! let value = true;
//! assert!(value == true);
//! assert!(!value == false);
//! ```
//!
//! Converting to optional values with [`BoolTrait::then_some`]:
//!
//! ```
//! use core::boolean::BoolTrait;
//!
//! let bool_value = true;
//! let result = bool_value.then_some(42_u8);
//! assert!(result == Option::Some(42));
//!
//! let bool_value = false;
//! let result = bool_value.then_some(42_u8);
//! assert!(result == Option::None);
//! ```

/// Basic trait for boolean operations.
/// Explicit import of `BoolTrait` is required with `use core::boolean::BoolTrait;`.
#[generate_trait]
pub impl BoolImpl<T, +Drop<T>> of BoolTrait<T> {
/// Returns `Some(t)` if the `bool` is `true`, or `None` otherwise.
/// Returns `Option::Some(t)` if the `bool` is `true`, `Option::None` otherwise.
///
/// # Examples
///
Expand Down