2a: Unit Logic

+biff

A +unit as argument.

Applies a $gate .b that produces a +unit to the unwrapped value of +unit .a (.u.a). If .a is empty, ~ is produced.

Accepts

.a is a +unit.

.b is a $gate that accepts a $noun and produces a +unit.

Produces

A +unit.

Source

++  biff
  |*  [a=(unit) b=$-(* (unit))]
  ?~  a  ~
  (b u.a)

Examples

> (biff (some 5) |=(a=@ (some (add a 2))))
[~ u=7]

+bind

Non-unit $gate to +unit, producing +unit.

Applies a $gate .b to the value (.u.a) of a +unit .a, producing a +unit. Used when you want a $gate that does not accept or produce a +unit to both accept and produce a +unit.

Accepts

.a is a +unit.

.b is a gate.

Produces

A +unit.

Source

Examples


+bond

Replace null.

Replaces an empty +unit .b with the product of a called +trap .a. If the +unit is not empty, then the original +unit is produced.

Accepts

.a is a +trap.

.b is a +unit.

Produces

Either the product of .a or the value inside of +unit .b.

Source

Examples


+both

Group +unit values into pair.

Produces ~ if either .a or .b are empty. Otherwise, produces a +unit whose value is a cell of the values of two input +units .a and .b.

Accepts

.a is a +unit.

.b is a +unit.

Produces

A +unit of the two initial values.

Source

Examples


+clap

Combine two +units with a gate.

Applies a binary $gate .c (which does not usually accept or produce a +unit) to the values of two +units, .a and .b, producing a +unit.

If .a is null, produces .b. If .b is null, produces .a. Otherwise, produces the product of .c in a +unit.

Accepts

.a is a +unit.

.b is a +unit.

.c is a $gate that performs a binary operation.

Produces

A +unit.

Source

Examples


+clef

Compose two +units with a gate.

Applies a binary $gate .c (which does not usually accept +units) to the values of two +units, .a and .b, producing a +unit.

If .a or .b are null, produces null. Otherwise, produces the produce of .c.

Accepts

.a is a +unit.

.b is a +unit.

.c is a $gate that takes a +cell and produces a +unit.

Produces

A +unit.

Source

Examples


+drop

Convert a +unit to a list.

Makes a +list of the unwrapped value (.u.a) of a +unit .a.

Accepts

.a is a +unit.

Produces

A list.

Source

Examples


+fall

Give +unit a default value.

Produces a default value .b for a +unit .a in cases where .a is null.

Accepts

.a is a +unit.

.b is a $noun that's used as the default value.

Produces

Either a $noun .b or the unwrapped value of +unit .a.

Source

Examples


+flit

Make filter.

Accepts $gate .a which produces a $flag. Applies .a to .b, producing .b wrapped in a +unit if true, otherwise produces null.

+flit is a wet $gate that takes .a and produces a new wet $gate that takes .b.

Accepts

.a is a $gate which produces a $flag, and is the sample of the outer wet gate.

.b is any $noun, and is the sample of the inner wet gate.

Produces

A (unit [type]), where [type] is the type of .b.

Source

Examples


+hunt

First of units.

Apply binary $gate .ord, which produces a $flag, to units .a and .b. Produce .a if true and .b if false. If .a is null, produce .b. If .b is null, produce .a.

This allows selecting between two units by some rule.

Accepts

.ord is a $-(^ ?) - a binary $gate that produces a $flag.

.a is a +unit.

.b is a +unit.

Produces

A +unit.

Source

Examples


+lift

Curried bind.

Accepts $gate .a and produces a $gate that accepts +unit .b to which it applies .a. Used when you want a $gate that does not accept or produce a +unit to both accept and produce a +unit.

Accepts

.a is a $mold.

.b is a +unit.

Produces

A +unit.

Source

Examples


+mate

Choose.

Accepts two +units .a and .b whose values are expected to be equivalent. If either is empty, then the value of the other is produced. If neither are empty, it asserts that both values are the same and produces that value. If the assertion fails, +mate crashes with 'mate' in the stack trace.

Accepts

.a is a +unit.

.b is a +unit.

Produces

A +unit or crash.

Source

Examples


+need

Unwrap +unit.

Retrieve the value from a +unit and crash if the +unit is null.

Accepts

.a is a +unit.

Produces

Either the unwrapped value of .a (.u.a), or crash.

Source

Examples


+some

Wrap value in a +unit.

Takes any $noun .a and produces a +unit with the value set to .a.

Accepts

.a is a $noun.

Produces

A +unit.

Source

Examples


Last updated