From 25ba08a6e714798977583228459a7287816198d4 Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Sat, 5 Dec 2020 17:02:56 +0700 Subject: [PATCH] add functions ltov and vtol --- README.md | 2 ++ src/Lib/Collections.php | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index cf04a23..817c942 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,8 @@ list | `(list 1 2 3)` | `(1 2 3)` | Create a new list. vector | `(vector 1 2 3)` | `[1 2 3]` | Create a new vector. range | `(range 2 5)` | `[2 3 4]` | Create a vector with integer values from first to argument (inclusive) to second argument (exclusive). range | `(range 5)` | `[0 1 2 3 4]` | Range can also be used with one argument in which case it is used as length for a vector of integers starting from 0. +ltov | `(ltov '(1 2 3))` | `[1 2 3]` | Convert list to vector. +vtol | `(vtol [1 2 3])` | `(1 2 3)` | Convert vector to list. empty? | `(empty? [])` | `true` | Return true if collection is empty, otherwise false. get | `(get [1 2 3] 0)` | `1` | Return the nth element from a sequence, or the corresponding value for the given key from a hash-map. len | `(len [1 2 3])` | `3` | Return the number of elements in a collection. diff --git a/src/Lib/Collections.php b/src/Lib/Collections.php index 6889a62..2b4f584 100644 --- a/src/Lib/Collections.php +++ b/src/Lib/Collections.php @@ -42,6 +42,16 @@ class Collections implements ILib } )); + // Conversion + + $env->set('ltov', new CoreFunc('ltov', 'Convert list to vector.', 1, 1, + fn (Seq $a) => new Vector($a->getData()) + )); + + $env->set('vtol', new CoreFunc('vtol', 'Convert vector to list.', 1, 1, + fn (Seq $a) => new MList($a->getData()) + )); + // Read information $env->set('empty?', new CoreFunc('empty?', 'Return true if collection is empty.', 1, 1,