优雅的coffee
优雅的东西会长久吗? 不一定, 更大可能是被淘汰, 因为看见优雅, 很难….
顺便悼念死掉的homesite, 已经拔掉氧气管但是还没埋的freemind, 可能还插着氧气管的coffee, ruby, 不是被遗忘就是被误用的swimlane
用分隔符拆分一个字符串为2部分(也就是说, 只有第一个分隔符有效)
# 正常js写法, 三元运算符?:
const markerIndex = content.indexOf(marker);
const right = markerIndex === -1 ? content : content.substring(0, markerIndex);
const left = markerIndex === -1 ? '' : content.substring(markerIndex + marker.length);
# 可能有些人喜欢这么写, 逻辑判断||, &&, 这里是coffee模拟用了and和or
markerIndex = content.indexOf marker
right = (markerIndex is -1 and content) or content.substring(0, markerIndex)
left = (markerIndex is -1 and '') or content.substring(markerIndex + marker.length)
# 一般的coffee写法, 注意此时逻辑会比上面2种写法清晰很多, 一个if判断
markerIndex = content.indexOf marker
right, left = if markerIndex <0 then content,'' else content.substring(0, markerIndex), content.substring(markerIndex + marker.length)
# 真正的coffee写法, 没有if判断
[right, left...] = content.split marker
left = left.join marker
双循环
closeTabByPath = (fsPath) ->
# 双循环
for tabGroup in vscode.window.tabGroups.all
for tab in tabGroup.tabs
if tab.input?.uri?.toString() == uri.toString()
await vscode.window.tabGroups.close(tab)
# 平铺 ----唯一, 数据结构才是关键 ----
target = vscode.window.tabGroups.all
.flatMap((group) -> group.tabs)
.find((t) -> t.input?.uri?.fsPath == fsPath)
vscode.window.tabGroups.close(target) if target?
# 使用尾部for直接查找匹配的标签页, 这个本质还是双重循环
target = tab for tab in group.tabs when tab.input?.uri?.fsPath is fsPath for group in vscode.window.tabGroups.all
vscode.window.tabGroups.close(target) if target?
# 真使用推导式, ai统统搞不定, 这一行也是错的, 俺也搞不定, 不知道咋搞, 而且搞好了也是双重for循环
if tab = (t for g in vscode.window.tabGroups.all for t in g.tabs when t.input?.uri?.fsPath is fsPath)[0]
vscode.window.tabGroups.close(tab)