diff options
| -rw-r--r-- | doc/core.md | 19 | ||||
| -rw-r--r-- | init.fnl | 19 |
2 files changed, 24 insertions, 14 deletions
diff --git a/doc/core.md b/doc/core.md index 014be20..578efef 100644 --- a/doc/core.md +++ b/doc/core.md @@ -1467,18 +1467,25 @@ Function signature: (into ([]) ([to]) ([to from]) ([to xform from])) ``` -Returns a new coll consisting of `to` with all of the items of - `from` conjoined. A transducer `xform` may be supplied. +Returns a new coll consisting of `to` with all of the items of `from` +conjoined. A transducer `xform` may be supplied. ### Examples -Thransofmr a hash-map into a sequence of key-value pairs: +Insert items of one collection into another collection: + +```fennel +(assert-eq [1 2 3 :a :b :c] (into [1 2 3] "abc")) +(assert-eq {:a 2 :b 3} (into {:a 1} {:a 2 :b 3})) +``` + +Transform a hash-map into a sequence of key-value pairs: ``` fennel (assert-eq [[:a 1]] (into (vector) {:a 1})) ``` - Construct a hash-map from a sequence of key-value pairs: +You can also construct a hash-map from a sequence of key-value pairs: ``` fennel (assert-eq {:a 1 :b 2 :c 3} @@ -1808,9 +1815,7 @@ Takes a value `x` and returns an infinite lazy sequence of this value. ### Examples ``` fennel -(assert-eq 10 (accumulate [res 0 - _ x (pairs (take 10 (repeat 1)))] - (+ res x))) +(assert-eq 20 (reduce add (take 10 (repeat 2)))) ``` ## `repeatedly` @@ -1298,9 +1298,7 @@ collection is provided." # Examples ``` fennel -(assert-eq 10 (accumulate [res 0 - _ x (pairs (take 10 (repeat 1)))] - (+ res x))) +(assert-eq 20 (reduce add (take 10 (repeat 2)))) ```" [x] (seq* (lazy.repeat x))) @@ -2050,18 +2048,25 @@ raise an error." ;;; Into (defn into - "Returns a new coll consisting of `to` with all of the items of - `from` conjoined. A transducer `xform` may be supplied. + "Returns a new coll consisting of `to` with all of the items of `from` +conjoined. A transducer `xform` may be supplied. # Examples -Thransofmr a hash-map into a sequence of key-value pairs: +Insert items of one collection into another collection: + +```fennel +(assert-eq [1 2 3 :a :b :c] (into [1 2 3] \"abc\")) +(assert-eq {:a 2 :b 3} (into {:a 1} {:a 2 :b 3})) +``` + +Transform a hash-map into a sequence of key-value pairs: ``` fennel (assert-eq [[:a 1]] (into (vector) {:a 1})) ``` - Construct a hash-map from a sequence of key-value pairs: +You can also construct a hash-map from a sequence of key-value pairs: ``` fennel (assert-eq {:a 1 :b 2 :c 3} |