-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from zanllp/dev-pattern-matching
使用模式匹配重写部分代码
- Loading branch information
Showing
3 changed files
with
29 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,24 @@ | ||
/*const dd = () => { | ||
const obj = { id: start_timer(() => log('call'), 30) } | ||
make_promise(cb => { | ||
fetch('http://127.0.0.1:8890', { method: 'get' }).then(v => { | ||
log(v.err_msg) | ||
remove_timer(obj.id) | ||
cb(v) | ||
}) | ||
}) | ||
} | ||
dd().then(v => log(f('end {}', v.keys().join(',')))) | ||
|
||
const delayExec = (fn, timeout = 1000) => start_timer(fn,timeout, true) | ||
*/ | ||
|
||
const json_str = fs.read("/Users/wuqinchuan/Desktop/project/agumi/canada.json") | ||
|
||
const j = json.parse(json_str) | ||
@{ | ||
const fn = (node) => { | ||
const t = typeof(node) | ||
(t == "object") ? @{ | ||
node.values().select(fn) | ||
} : (t == "array") ? @{ | ||
node.select(fn) | ||
} : log(node) | ||
|
||
} | ||
// fn(j) | ||
const arr = [] | ||
const fn = (node) => match (typeof(node)) { | ||
"object" : node.values().select(fn), | ||
"array": node.select(fn), | ||
_: arr.push(node) | ||
} | ||
fn(j) | ||
fs.write("./res.json", json.stringify(arr)) | ||
} | ||
/* | ||
const t = time() | ||
for(5, () => { | ||
// json.parse(json_str) | ||
json.parse(json_str) | ||
}) | ||
log((time() - t)/5) | ||
|
||
const match = (params) => { | ||
assert(typeof(params), "object") | ||
full_log(params.values()) | ||
} | ||
|
||
match({ | ||
"hello": 1, | ||
world: 2 | ||
}) | ||
*/ |