123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #elvdoc:fn ns
- #
- # ```elvish
- # ns $map
- # ```
- #
- # Constructs a namespace from `$map`, using the keys as variable names and the
- # values as their values. Examples:
- #
- # ```elvish-transcript
- # ~> var n = (ns [&name=value])
- # ~> put $n[name]
- # ▶ value
- # ~> var n: = (ns [&name=value])
- # ~> put $n:name
- # ▶ value
- # ```
- #elvdoc:fn make-map
- #
- # ```elvish
- # make-map $input?
- # ```
- #
- # Outputs a map from the [value inputs](#value-inputs), each of which must be
- # an iterable value with with two elements. The first element of each value
- # is used as the key, and the second element is used as the value.
- #
- # If the same key appears multiple times, the last value is used.
- #
- # Examples:
- #
- # ```elvish-transcript
- # ~> make-map [[k v]]
- # ▶ [&k=v]
- # ~> make-map [[k v1] [k v2]]
- # ▶ [&k=v2]
- # ~> put [k1 v1] [k2 v2] | make-map
- # ▶ [&k1=v1 &k2=v2]
- # ~> put aA bB | make-map
- # ▶ [&a=A &b=B]
- # ```
- #elvdoc:fn assoc
- #
- # ```elvish
- # assoc $container $k $v
- # ```
- #
- # Output a slightly modified version of `$container`, such that its value at `$k`
- # is `$v`. Applies to both lists and to maps.
- #
- # When `$container` is a list, `$k` may be a negative index. However, slice is not
- # yet supported.
- #
- # ```elvish-transcript
- # ~> assoc [foo bar quux] 0 lorem
- # ▶ [lorem bar quux]
- # ~> assoc [foo bar quux] -1 ipsum
- # ▶ [foo bar ipsum]
- # ~> assoc [&k=v] k v2
- # ▶ [&k=v2]
- # ~> assoc [&k=v] k2 v2
- # ▶ [&k2=v2 &k=v]
- # ```
- #
- # Etymology: [Clojure](https://clojuredocs.org/clojure.core/assoc).
- #
- # @cf dissoc
- #elvdoc:fn dissoc
- #
- # ```elvish
- # dissoc $map $k
- # ```
- #
- # Output a slightly modified version of `$map`, with the key `$k` removed. If
- # `$map` does not contain `$k` as a key, the same map is returned.
- #
- # ```elvish-transcript
- # ~> dissoc [&foo=bar &lorem=ipsum] foo
- # ▶ [&lorem=ipsum]
- # ~> dissoc [&foo=bar &lorem=ipsum] k
- # ▶ [&lorem=ipsum &foo=bar]
- # ```
- #
- # @cf assoc
- #elvdoc:fn has-value
- #
- # ```elvish
- # has-value $container $value
- # ```
- #
- # Determine whether `$value` is a value in `$container`.
- #
- # Examples, maps:
- #
- # ```elvish-transcript
- # ~> has-value [&k1=v1 &k2=v2] v1
- # ▶ $true
- # ~> has-value [&k1=v1 &k2=v2] k1
- # ▶ $false
- # ```
- #
- # Examples, lists:
- #
- # ```elvish-transcript
- # ~> has-value [v1 v2] v1
- # ▶ $true
- # ~> has-value [v1 v2] k1
- # ▶ $false
- # ```
- #
- # Examples, strings:
- #
- # ```elvish-transcript
- # ~> has-value ab b
- # ▶ $true
- # ~> has-value ab c
- # ▶ $false
- # ```
- #elvdoc:fn has-key
- #
- # ```elvish
- # has-key $container $key
- # ```
- #
- # Determine whether `$key` is a key in `$container`. A key could be a map key or
- # an index on a list or string. This includes a range of indexes.
- #
- # Examples, maps:
- #
- # ```elvish-transcript
- # ~> has-key [&k1=v1 &k2=v2] k1
- # ▶ $true
- # ~> has-key [&k1=v1 &k2=v2] v1
- # ▶ $false
- # ```
- #
- # Examples, lists:
- #
- # ```elvish-transcript
- # ~> has-key [v1 v2] 0
- # ▶ $true
- # ~> has-key [v1 v2] 1
- # ▶ $true
- # ~> has-key [v1 v2] 2
- # ▶ $false
- # ~> has-key [v1 v2] 0:2
- # ▶ $true
- # ~> has-key [v1 v2] 0:3
- # ▶ $false
- # ```
- #
- # Examples, strings:
- #
- # ```elvish-transcript
- # ~> has-key ab 0
- # ▶ $true
- # ~> has-key ab 1
- # ▶ $true
- # ~> has-key ab 2
- # ▶ $false
- # ~> has-key ab 0:2
- # ▶ $true
- # ~> has-key ab 0:3
- # ▶ $false
- # ```
- #elvdoc:fn keys
- #
- # ```elvish
- # keys $map
- # ```
- #
- # Put all keys of `$map` on the structured stdout.
- #
- # Example:
- #
- # ```elvish-transcript
- # ~> keys [&a=foo &b=bar &c=baz]
- # ▶ a
- # ▶ c
- # ▶ b
- # ```
- #
- # Note that there is no guaranteed order for the keys of a map.
|