在 C++17 後要 sum type 可以這樣用:
#include<variant>
// data Solution = Surface Vector3 Double |
// Line Vector3 Vector3 |
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode() : val(0), next(nullptr) {} | |
* ListNode(int x) : val(x), next(nullptr) {} | |
* ListNode(int x, ListNode *next) : val(x), next(next) {} | |
* }; | |
*/ |
https://developer.apple.com/library/archive/documentation/mac/pdf/Text.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/MoreMacintoshToolbox.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/MacintoshToolboxEssentials.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/ResEditReference.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/ImagingWithQuickDraw.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/MacOS_RT_Architectures.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/Processes/Vertical_Retrace_Mgr.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/Sound/Sound_Input_Manager.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/Networking/DDP.pdf | |
https://developer.apple.com/library/archive/documentation/mac/pdf/Operating_System_Utilities/PRAM_Utilities.pdf |
const IDX = { | |
VHS: { P2: 6, P3: 7, P4: 8, P5: 9, P6: 10 } | |
} | |
const nudgePoints = (elementIndexes) => assign((ctx, evt) => { | |
const [x, y] = [evt.clientX, evt.clientY] | |
const [sx, sy] = ctx.lastClientPoint | |
const [dx, dy] = [x - sx, y - sy] | |
const paths = elementIndexes.map(idx => [0, ctx.groupIndex, idx]) | |
ctx.editorMethods.nudgeElementsAtPath(dx, dy, paths) | |
return { ...ctx, lastClientPoint: [x, y] } |
const pinchMachine = Machine({ | |
id: 'pinch', | |
initial: 'idle', | |
context: { | |
onPinch: () => {}, | |
onPan: ([dx, dy]) => {}, | |
finishPinch: () => {}, | |
onSingleTouch: { | |
touchStart: (currentPoint) => {}, | |
touchMove: (currentPoint) => {}, |
// Copyright (c) the JPEG XL Project | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, |
const m = Machine({ | |
id: 'websocket', | |
context: { | |
devices: [] | |
}, | |
initial: 'offline', | |
states: { | |
offline: { | |
on: { | |
CONNECT: 'trying' |
// | |
// main.swift | |
// ShitWeb | |
// | |
// Created by Yung-Luen Lan on 2020/5/14. | |
// Copyright © 2020 Yung-Luen Lan. All rights reserved. | |
// | |
import Foundation | |
import Network |
前提: Syntax很簡單,不用look ahead,而且都會知道要讀多少byte(沒有那種「讀到0x00為止」)
我的作法看起來長這樣:
const msgParser = expect([10, 10, 20], (datetime, messageType, messageID) => {
switch (messageType) {
case "HI":
expect([10, 10], (senderID, senderName) => {
// connect