2title = "2a: Unit Logic"
9[`Unit`](/docs/hoon/reference/stdlib/1c#unit) as argument
11Applies a function `b` that produces a [`unit`](/docs/hoon/reference/stdlib/1c#unit) to the unwrapped value of [`unit`](/docs/hoon/reference/stdlib/1c#unit)
12`a` (`u.a`). If `a` is empty, `~` is produced.
16`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
18`b` is a function that accepts a [`noun`](/docs/glossary/noun) and produces a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
22A [`unit`](/docs/hoon/reference/stdlib/1c#unit).
28 |* [a=(unit) b=$-(* (unit))]
36> (biff (some 5) |=(a=@ (some (add a 2))))
41> (biff ~ |=(a=@ (some (add a 2))))
49Non-unit function to [`unit`](/docs/hoon/reference/stdlib/1c#unit), producing [`unit`](/docs/hoon/reference/stdlib/1c#unit)
51Applies a function `b` to the value (`u.a`) of a [`unit`](/docs/hoon/reference/stdlib/1c#unit) `a`, producing
52a [`unit`](/docs/hoon/reference/stdlib/1c#unit). Used when you want a function that does not accept or produce a
53[`unit`](/docs/hoon/reference/stdlib/1c#unit) to both accept and produce a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
57`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
63A [`unit`](/docs/hoon/reference/stdlib/1c#unit).
77> (bind ((unit @) [~ 97]) ,@t)
83> (bind ((unit @) [~ 2]) a)
93Replaces an empty [`unit`](/docs/hoon/reference/stdlib/1c#unit) `b` with the product of a called [`trap`](/docs/glossary/trap)
94`a`. If the [`unit`](/docs/hoon/reference/stdlib/1c#unit) is not empty, then the original [`unit`](/docs/hoon/reference/stdlib/1c#unit) is produced.
98`a` is a [`trap`](/docs/glossary/trap).
100`b` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
104Either the product of `a` or the value inside of [`unit`](/docs/hoon/reference/stdlib/1c#unit) `b`.
121 > ((bond |.((bex 10))) ~)
126 > ((bond |.((bex 10))) (slaw %ud '123'))
134Group [`unit`](/docs/hoon/reference/stdlib/1c#unit) values into pair
136Produces `~` if either `a` or `b` are empty. Otherwise, produces a
137[`unit`](/docs/hoon/reference/stdlib/1c#unit) whose value is a cell of the values of two input [`units`](/docs/hoon/reference/stdlib/1c#unit) `a` and
142`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
144`b` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
148A [`unit`](/docs/hoon/reference/stdlib/1c#unit) of the two initial values.
154 |* [a=(unit) b=(unit)]
163> (both (some 1) (some %b))
176Combine two [`units`](/docs/hoon/reference/stdlib/1c#unit) with function
178Applies a binary function `c`--which does not usually accept or produce a
179[`unit`](/docs/hoon/reference/stdlib/1c#unit)-- to the values of two [`units`](/docs/hoon/reference/stdlib/1c#unit), `a` and `b`, producing a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
181If `a` is null, produces `b`. If `b` is null, produces `a`. Otherwise, produces the produce of `c` in a `unit`.
185`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
187`b` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
189`c` is a function that performs a binary operation.
193A [`unit`](/docs/hoon/reference/stdlib/1c#unit).
199 |* [a=(unit) b=(unit) c=_=>(~ |=(^ +<-))]
208> (clap ~ `'b' |=([a=@tD b=@tD] `tape`[a b ~]))
213> (clap `'a' ~ |=([a=@tD b=@tD] `tape`[a b ~]))
218> (clap `'a' `'b' |=([a=@tD b=@tD] `tape`[a b ~]))
226Compose two [`units`](/docs/hoon/reference/stdlib/1c#unit) with function
228Applies a binary function `c`--which does not usually accept [`units`](/docs/hoon/reference/stdlib/1c#unit)-- to the values of two [`units`](/docs/hoon/reference/stdlib/1c#unit), `a` and `b`, producing a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
230If `a` or `b` are null, produces null. Otherwise, produces the produce of `c`.
238`c` is a `gate` that takes a `cell` and produces a `unit`.
248 |* [a=(unit) b=(unit) c=_=>(~ |=(^ `+<-))]
257> (clef ~ `'b' |=([a=@tD b=@tD] `(unit tape)`[~ [a b ~]]))
262> (clef `'a' ~ |=([a=@tD b=@tD] `(unit tape)`[~ [a b ~]]))
267> (clef `'a' `'b' |=([a=@tD b=@tD] `(unit tape)`[~ [a b ~]]))
275[`Unit`](/docs/hoon/reference/stdlib/1c#unit) to list
277Makes a [`++list`](/docs/hoon/reference/stdlib/1c#list) of the unwrapped value (`u.a`) of a [`unit`](/docs/hoon/reference/stdlib/1c#unit) `a`.
281`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
299> =a ((unit @) [~ 97])
314Give [`unit`](/docs/hoon/reference/stdlib/1c#unit) a default value
316Produces a default value `b` for a [`unit`](/docs/hoon/reference/stdlib/1c#unit) `a` in cases where `a` is null.
320`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
322`b` is a [`noun`](/docs/glossary/noun) that's used as the default value.
326Either a [`noun`](/docs/glossary/noun) `b` or the unwrapped value of [`unit`](/docs/hoon/reference/stdlib/1c#unit) `a`.
351Accepts gate `a` which produces a `?`. Applies `a` to `b`, producing `b` wrapped in a `unit` if true, otherwise produces null.
353`+flit` is a wet gate that takes `a` and produces a new wet gate that takes `b`.
357`a` is a `gate` which produces `?`, and is the sample of the outer wet gate.
359`b` is any `noun`, and is the sample of the inner wet gate.
363`(unit [type])`, where `[type]` is the type of `b`.
377> =f (flit |=(=@ud ?:(=(ud 1) %.y %.n)))
390Apply binary gate `ord`, which produces a `?`, 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`.
392This allows selecting between two units by some rule.
396`ord` is a `$-(^ ?)` - a binary gate that produces `?`.
410 |* [ord=$-(^ ?) a=(unit) b=(unit)]
417 ?:((ord u.a u.b) a b)
443Accepts function `a` and produces a function that accepts [`unit`](/docs/hoon/reference/stdlib/1c#unit)
444`b` to which it applies `a`. Used when you want a function that does not accept
445or produce a [`unit`](/docs/hoon/reference/stdlib/1c#unit) to both accept and produce a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
451`b` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
455A [`unit`](/docs/hoon/reference/stdlib/1c#unit).
469> ((lift dec) `(unit @)`~)
474> ((lift dec) `(unit @)`[~ 20])
484Accepts two [`units`](/docs/hoon/reference/stdlib/1c#unit) `a` and `b` whose values are expected to be
485equivalent. If either is empty, then the value of the other is produced.
486If neither are empty, it asserts that both values are the same and
487produces that value. If the assertion fails, `++mate` crashes with
488`'mate'` in the stack trace.
492`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
494`b` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
498A [`unit`](/docs/hoon/reference/stdlib/1c#unit) or crash.
504 |* [a=(unit) b=(unit)]
507 ?.(=(u.a u.b) ~>(%mean.'mate' !!) a)
513> =a ((unit @) [~ 97])
514> =b ((unit @) [~ 97])
520> =a ((unit @) [~ 97])
527> =a ((unit @) [~ 97])
528> =b ((unit @) [~ 98])
538Unwrap [`unit`](/docs/hoon/reference/stdlib/1c#unit)
540Retrieve the value from a [`unit`](/docs/hoon/reference/stdlib/1c#unit) and crash if the [`unit`](/docs/hoon/reference/stdlib/1c#unit) is null.
544`a` is a [`unit`](/docs/hoon/reference/stdlib/1c#unit).
548Either the unwrapped value of `a` (`u.a`), or crash.
556 ?~ a ~>(%mean.'need' !!)
563> =a ((unit [@t @t]) [~ ['a' 'b']])
569> =a ((unit @ud) [~ 17])
584Wrap value in a [`unit`](/docs/hoon/reference/stdlib/1c#unit)
586Takes any [`noun`](/docs/glossary/noun) `a` and produces a [`unit`](/docs/hoon/reference/stdlib/1c#unit) with the value set to `a`.
590`a` is a [`noun`](/docs/glossary/noun).
594A [`unit`](/docs/hoon/reference/stdlib/1c#unit).
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list