2i: Map Logic

+by

Map operations.

Container arm for +map operation arms. A +map is a +set of key-value pairs. The contained arms inherit its sample +map, .a.

Accepts

.a is a +map.

Source

++  by
  ~/  %by
  =|  a=(tree (pair))  ::  (map)
  =*  node  ?>(?=(^ a) n.a)
  |@

Examples

> ~(. by (malt (limo ~[a+1 b+2 c+3])))
< 27.jus
  [   a
    ?(
      %~
      [ n=[?(p=%a p=%b p=%c) q=@ud]
        l=nlr([p=?(%a %b %c) q=@ud])
        r=nlr([p=?(%a %b %c) q=@ud])
      ]
    )
    <123.zao 46.hgz 1.pnw %140>
  ]
>

+all:by

Logical AND.

Computes the logical AND on the results of slamming every element in +map .a with $gate .b.

Accepts

.a is a +map, and is the sample of +by.

.b is a $gate.

Produces

A $flag.

Source

Examples


+any:by

Logical OR.

Computes the logical OR on the results of slamming every element with $gate .b.

Accepts

.a is a +map, and is the sample of +by.

.b is a wet $gate.

Produces

A $flag.

Source

Examples


+apt:by

Check correctness.

Computes whether .a has a correct horizontal order and a correct vertical order, producing a $flag.

Accepts

.a is a +map.

Produces

A $flag.

Source

Examples

Discussion

See section 2f for more information on $noun ordering.

+bif:by

Bifurcate.

Splits +map .a into two +maps .l and .r, which contain the items either side of key .b with value .c but not including the pair of key .b and value .c.

Accepts

.a is a +map, and is the sample of +by.

.b is a $noun.

.c is a $noun.

Produces

A cell of two +maps.

Source

Examples

Discussion

Note that +maps are horizontally ordered by the +mug hash of their keys and vertically ordered by the double-+mug hash of their keys. This means bifurcating the +map (malt ~[10^10 20^20 30^30 40^40 50^50]) at 30^30 will not produce [{10^10 20^20} {40^40 50^50}], but rather [{20^20} {10^10 40^40 50^50}] due to the tree structure resulting from their +mug hashes.


+del:by

Delete.

Produces +map .a with the element located at key .b removed.

Accepts

.a is a +map, and is the sample of +by.

.b is a key as a $noun.

Produces

A +map.

Source

Examples


+dif:by

Difference.

Computes the difference between .a and .b, producing the +map of key-value pairs in .a whose keys are not in .b.

Accepts

.a is a +map, and is the sample of +by.

.b is a +map.

Produces

A +map.

Source

Examples

Discussion

This only compares keys, so if both +maps contain the same key with different values, that key-value pair is not considered a difference and will not be included in the resulting +map.


+dig:by

Address of key.

Produce the address of key .b within +map .a.

Accepts

.a is a +map, and is the sample of +by.

.b is a key as a $noun.

Produces

A unit.

Source

Examples


+gas:by

Merge.

Like Clojure's merge. Insert a list of key-value pairs .b into +map .a. For a key which exists in both .a and .b, the value is replaced with the value in .b.

Accepts

.a is a +map, and is the sample of +by.

.b is a list of cells of key-value $nouns .p and .q.

Produces

A +map.

Source

Examples


+get:by

Grab unit value.

Produce the unit value of the value located at key .b within +map .a.

Accepts

.a is a +map, and is the sample of +by.

.b is a key as a $noun.

Produces

A unit.

Source

Examples


+got:by

Assert.

Produce the value located at key .b within +map .a. Crash if key .b does not exist.

Accepts

.a is a +map, and is the sample of +by.

.b is a key as a $noun.

Produces

A $noun.

Source

Examples


+gut:by

Grab value with default.

Produce the value located at key .b within +map .a. Use default value .c if key does not exist.

Accepts

.a is a +map, and is the sample of +by.

.b is a key as a $noun.

.c is a $noun.

Produces

A $noun.

Source

Examples


+has:by

Key existence check.

Checks whether +map .a contains an element with key .b, producing a $flag.

Accepts

.a is a +map, and is the sample of +by.

.b is a key as a $noun.

Produces

A $flag.

Source

Examples


+int:by

Intersection.

Produces a +map of the (key) intersection between two +maps of the same type, .a and .b. If both +maps have an identical key that point to different values, the element from +map .b is used.

Accepts

.a is a +map, and is the sample of +by.

.b is a +map.

Produces

A +map.

Source

Examples


+jab:by

Transform value.

Produce +map .a with the value at key .b transformed by $gate .c.

Accepts

.a is a +map, and is the sample of +by.

.b is a $noun, and a key in .a.

.c is a $gate.

Produces

A +map.

Source

Examples


+key:by

Set of keys.

Produces a +set of all keys in +map .a.

Accepts

.a is a +map, and is the sample of +by.

Produces

A +set.

Source

Examples


+mar:by

Add with validation.

Produces +map .a with the addition of key-value pair .b and .c, where the value is a nonempty unit.

Accept a $noun and a unit of a $noun of the type of the +map's keys and values, respectively. Validate that the value is not null and put the pair in the +map. If the value is null, delete the key.

Accepts

.a is a +map, and is the sample of +by.

.b is a $noun.

.c is a +unit.

Produces

A +map.

Source

Examples


+put:by

Add key-value pair.

Produces .a with the addition of the key-value pair of .b and .c.

Accepts

.a is a +map, and is the sample of +by.

.b is a key of the same type as the keys in .a.

.c is a value of the same type of the values in .a.

Produces

A +map.

Source

Examples


+rep:by

Reduce to product.

Accumulate elements of +map .a using $gate .b, producing a $noun.

Accepts

.a is a +map.

.b is a $gate.

Produces

A $noun.

Source

Examples

Discussion

The $gate will iteratively be fed a cell whose head is a key-value pair from the +map and whose tail is an accumulator, producing the final value of the accumulator.


+rib:by

Transform + product.

.c is a $gate with a sample like [[key value] accumulator] and a product like [accumulator [key value]]. Each key-value pair in +map .a is passed to .c and replaced with the key-value pair .c produced. The final value of the accumulator and the modified +map are returned. .b is the initial value of the accumulator.

Accepts

.a is a +map, and is the sample of +by.

.b is a $noun, and is the initial value of the accumulator.

.c is a $gate.

Produces

A cell of a $noun and a +map.

Source

Examples

In this example, all values less than three are changed to zero, and a list of their keys are produced along with the modified +map.

Discussion

Key-value pairs in the +map are transformed in their existing tree location. This means if you change the key, you'd likely produce a +map with an incorrect order, so typically you should only change the value.


+run:by

Transform values.

Iterates over every value in +map .a using $gate .b, producing a +map.

Accepts

.a is a +map, and is the sample of +by.

.b is a $gate.

Produces

A +map.

Source

Examples


+tap:by

Listify pairs.

Produces the list of all elements in +map .a.

Accepts

.a is a +map, and is the sample of +by.

Produces

A list.

Source

Examples


+uni:by

Union, merge.

Produces a +map of the union between the keys of .a and .b. If .b shares a key with .a, the tuple from .b is preserved.

Accepts

.a is a +map, and is the sample +by.

.b is a +map.

Produces

A +map.

Source

Examples


+uno:by

General union.

Produces a +map of the union between the keys of .a and .b. If .b shares a key with .a, $gate +meg is applied to both and its product is used as the new value of the key in question.

Accepts

.a is a +map, and is the sample of +by.

.b is a +map, and is the sample of ~(uno by a).

+meg is a $gate, and is the sample of (~(uno by a) b).

Produces

A +map.

Source

Examples


+urn:by

Turn (with key).

Iterates over every value in +map .a using $gate .b, which accepts both the key and the value of each element as its sample.

Accepts

.a is a +map.

.b is a $gate that accepts two $nouns.

Produces

A +map.

Source

Examples


+wyt:by

Depth.

Produce the size of the tree +map .a.

Accepts

.a is a +map, and is the sample of +by.

Produces

An $atom.

Source

Examples


+val:by

List of values.

Produces a list of all values in +map .a.

Accepts

.a is a +map.

Produces

A list.

Source

Examples


Last updated