kex docs Standard Library 0.4.0-alpha kex.run ↗

Blankableprelude

trait Blankable

Blankable: types that can be asked whether they hold anything meaningful.

A value is blank when it has no meaningful content: None, an empty or all-whitespace string, an empty collection, or false. The semantics are Rails's, and the point is the same: one question that works across types, so a validation does not need a different test per field.

"".blank?        # => true
"   ".blank?     # => true   (unlike "   ".empty?)
[].blank?        # => true
None.blank?      # => true
"hi".present?    # => true

present? is the negation, and is often what reads better:

fields.all? { |name, value| value.present? }

blank?

Returns true when the value holds nothing meaningful.

What that means is up to each type: whitespace-only for a string, no elements for a collection, None for an optional, false for a boolean.

blank? : Bool

Returns: Booltrue when the value is blank

Examples
"".blank?      # => true
"  ".blank?    # => true
"hi".blank?    # => false

make Bool implements Blankable

make Integer implements Blankable

blank?

Always false: every integer is a value, including zero.

blank? : Bool

Returns: Bool — always false

Examples
0.blank?    # => false
42.blank?   # => false

make Float implements Blankable

blank?

Always false: every float is a value, including zero.

blank? : Bool

Returns: Bool — always false

Examples
0.0.blank?   # => false

make String implements Blankable

make Optional<X> implements Blankable

blank?

Returns true for None and false for a Just: whatever it wraps.

Note that Just("") is present, not blank: the optional holds a value, even though that value is itself blank.

blank? : Bool

Returns: Booltrue for None

Examples
None.blank?        # => true
Just(1).blank?     # => false
Just("").blank?    # => false

make [X] implements Blankable

blank?

Returns true when the list has no elements.

blank? : Bool

Returns: Booltrue for the empty list

Examples
[].blank?         # => true
[1, 2].blank?     # => false

Reporting an empty result set

if matches.blank?
  IO.printLine("no matches")
end