Real.ordered? 🤘


#1

I was just admiring some of the craftsmanship in the latest drop! This one stuck out first as a “wait, huh?” moment that later turned into a smile when it clicked.

({Real} nums) Boolean
  [
  [nums.length <= 1] // treat 0 and 1 item as ordered
    or
    [
    !prev: nums.first!
    nums.all?[[prev <= item] and [prev := item true]]
    ]
  ]

image


#2

Half the reason why that method was added was to be an example. :madsci:

For anyone who is curious what we are talking about, this is the Real.ordered?() method. It determines if all the supplied numbers (num1 <= num2 <= … <= numN) are in order and returns true or false.

For example:

if Real.ordered?(num1 num2 num3 num4)
  [all_good]
else
  [not_ordered]