概要
map や list を人が見やすいように出力する Apex の紹介です。
巨大なコレクション型を inspect
で出力すると構造の把握が難しいですが、Apex を使用するとインテントや改行を入れてくれて見やすくなります。いわゆる pretty print です。
使用例
Apex.ap 変数
例えば、inspect
でこちらが出力されるようなコレクションで、
output_inspect
[kind: :SelectionSet, loc: [start: 0], selections: [[kind: :Field, loc: [start: 0], name: 'feedList', selectionSet: [kind: :SelectionSet, loc: [start: 0], selections: [[kind: :Field, loc: [start: 0], name: 'feeds', arguments: [[kind: :Argument, loc: [start: 0], name: 'count', value: [kind: :Variable, loc: [start: 0], name: 'count']]], selectionSet: [kind: :SelectionSet, loc: [start: 0], selections: [[kind: :Field, loc: [start: 0], name: 'id'], [kind: :Field, loc: [start: 0], name: 'title']]]]]]]]]
Apex ではこうなります。
output_apex
[
[0] kind: SelectionSet
[1] loc: [
[0] start: 0
]
[2] selections: [
[0] [
[0] kind: Field
[1] loc: [
[0] start: 0
]
[2] name: [
[0] 102
[1] 101
[2] 101
[3] 100
[4] 76
[5] 105
[6] 115
[7] 116
]
[3] selectionSet: [
[0] kind: SelectionSet
[1] loc: [
[0] start: 0
]
[2] selections: [
[0] [
[0] kind: Field
[1] loc: [
[0] start: 0
]
[2] name: [
[0] 102
[1] 101
[2] 101
[3] 100
[4] 115
]
[3] arguments: [
[0] [
[0] kind: Argument
[1] loc: [
[0] start: 0
]
[2] name: [
[0] 99
[1] 111
[2] 117
[3] 110
[4] 116
]
[3] value: [
[0] kind: Variable
[1] loc: [
[0] start: 0
]
[2] name: [
[0] 99
[1] 111
[2] 117
[3] 110
[4] 116
]
]
]
]
[4] selectionSet: [
[0] kind: SelectionSet
[1] loc: [
[0] start: 0
]
[2] selections: [
[0] [
[0] kind: Field
[1] loc: [
[0] start: 0
]
[2] name: [
[0] 105
[1] 100
]
]
[1] [
[0] kind: Field
[1] loc: [
[0] start: 0
]
[2] name: [
[0] 116
[1] 105
[2] 116
[3] 108
[4] 101
]
]
]
]
]
]
]
]
]
]
文字が数字の配列になっているのは Char List だからです。文字は普通に表示されます。
最後に
Char List も insect
のように出力できるようにしてプルリクとかしたいのですが、まだ力不足でさくっとはできそうもないので、時間ができたときにでもやってみようと思っています。