Repository: syuilo/aiscript
Pull request #273 (2023-05-18 15:04:48)

Obj:vals()の追加
# What
<!-- このPRで何をしたのか？ どう変わるのか？ -->
<!-- What did you do with this PR? How will it change things? -->
新しいstd関数のObj:vals()を追加します。

# Why
<!-- なぜそうするのか？ どういう意図なのか？ 何が困っているのか？ -->
<!-- Why do you do it? What are your intentions? What is the problem? -->
欲しいと思う場面が結構あったので作成しました。

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/syuilo/aiscript/pull/273?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo) Report
> :exclamation: No coverage uploaded for pull request base (`master@4c9e931`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo#section-missing-base-commit).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##             master     #273   +/-   ##
=========================================
  Coverage          ?   88.34%           
=========================================
  Files             ?       19           
  Lines             ?     2916           
  Branches          ?      485           
=========================================
  Hits              ?     2576           
  Misses            ?      331           
  Partials          ?        9           
```


| [Impacted Files](https://app.codecov.io/gh/syuilo/aiscript/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo) | Coverage Δ | |
|---|---|---|
| [src/interpreter/lib/std.ts](https://app.codecov.io/gh/syuilo/aiscript/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo#diff-c3JjL2ludGVycHJldGVyL2xpYi9zdGQudHM=) | `79.90% <100.00%> (ø)` | |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/syuilo/aiscript/pull/273?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 83a19fa..e3150d1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
 [Read translated version (en)](./translations/en/CHANGELOG.md)
 
+- オブジェクトの値を配列化する`Obj:vals`を追加
+
 # 0.13.3
 - 乱数を生成するとき引数の最大値を戻り値に含むように
 
diff --git a/docs/std.md b/docs/std.md
index 2bf67c0..7fa5d3f 100644
--- a/docs/std.md
+++ b/docs/std.md
@@ -208,8 +208,9 @@ arr.sortの比較関数として使用できます。
 ## :: Obj
 
 ### @Obj:keys(_v_: obj): arr
-
+### @Obj:vals(_v_: obj): arr
 ### @Obj:kvs(_v_: obj): arr
+オブジェクトのキー、値、キーと値の組を配列にして返します。
 
 ### @Obj:get(_v_: obj, _key_: str): value
 
diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts
index 09b8f94..bec9de8 100644
--- a/src/interpreter/lib/std.ts
+++ b/src/interpreter/lib/std.ts
@@ -315,6 +315,11 @@ export const std: Record<string, Value> = {
 		return ARR(Array.from(obj.value.keys()).map(k => STR(k)));
 	}),
 
+	'Obj:vals': FN_NATIVE(([obj]) => {
+		assertObject(obj);
+		return ARR(Array.from(obj.value.values()));
+	}),
+
 	'Obj:kvs': FN_NATIVE(([obj]) => {
 		assertObject(obj);
 		return ARR(Array.from(obj.value.entries()).map(([k, v]) => ARR([STR(k), v])));


Test patch:
diff --git a/test/index.ts b/test/index.ts
index 4b4eada..ff7a7ac 100644
--- a/test/index.ts
+++ b/test/index.ts
@@ -2502,6 +2502,15 @@ describe('std', () => {
 			eq(res, ARR([STR('a'), STR('b'), STR('c')]));
 		});
 
+		test.concurrent('vals', async () => {
+			const res = await exe(`
+			let o = { _nul: null; _num: 24; _str: 'hoge'; _arr: []; _obj: {}; }
+
+			<: Obj:vals(o)
+			`);
+			eq(res, ARR([NULL, NUM(24), STR('hoge'), ARR([]), OBJ(new Map([]))]));
+		});
+
 		test.concurrent('kvs', async () => {
 			const res = await exe(`
 			let o = { a: 1; b: 2; c: 3; }