This file contains hidden or 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
public struct DTOMacro: MemberMacro { | |
public static func expansion( | |
of node: AttributeSyntax, | |
providingMembersOf declaration: some DeclGroupSyntax, | |
in context: some MacroExpansionContext | |
) throws -> [DeclSyntax] { | |
guard let structDecl = declaration as? StructDeclSyntax | |
else { | |
return [] | |
} |
This file contains hidden or 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
// MARK: - PropertyMacro | |
public struct PropertyMacro: AccessorMacro { | |
public static func expansion( | |
of node: AttributeSyntax, | |
providingAccessorsOf declaration: some DeclSyntaxProtocol, | |
in context: some MacroExpansionContext | |
) throws -> [AccessorDeclSyntax] { | |
guard let varDecl = declaration.as(VariableDeclSyntax.self) else { |
This file contains hidden or 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
StructDeclSyntax | |
├─attributes: AttributeListSyntax | |
│ ╰─[0]: AttributeSyntax | |
│ ├─atSign: atSign | |
│ ╰─attributeName: IdentifierTypeSyntax | |
│ ╰─name: identifier("DTO") | |
├─modifiers: DeclModifierListSyntax | |
├─structKeyword: keyword(SwiftSyntax.Keyword.struct) | |
├─name: identifier("TestModel") | |
╰─memberBlock: MemberBlockSyntax |
This file contains hidden or 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
final class LeetCode2191 { | |
func sortJumbled(_ mapping: [Int], _ nums: [Int]) -> [Int] { | |
zip(nums, nums.map { mapped(mapping, $0) }) | |
.sorted { $0.1 < $1.1 } | |
.map(\.0) | |
} | |
private func mapped(_ mapping: [Int], _ number: Int, _ base: Int = 1) -> Int { | |
if number < 10 { | |
base * mapping[number % 10] |
This file contains hidden or 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
final class LeetCode2191 { | |
typealias Item = (original: Int, mapped: Int) | |
func sortJumbled(_ mapping: [Int], _ nums: [Int]) -> [Int] { | |
nums | |
.map { convert($0, using: mapping) } | |
.sorted { | |
$0.mapped < $1.mapped | |
} | |
.map(\.original) | |
} |
This file contains hidden or 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
final class Solution { | |
func lengthOfLIS(_ nums: [Int]) -> Int { | |
var tails: [Int] = [nums[0]] | |
for index in 1 ..< nums.count { | |
if nums[index] > tails.last! { | |
tails.append(nums[index]) | |
} else { | |
tails[binarySearch(tails, target: nums[index])] = nums[index] |
This file contains hidden or 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
final class Solution { | |
func lengthOfLIS(_ nums: [Int]) -> Int { | |
var dp: [Int] = .init(repeating: 1, count: nums.count) | |
for i in 1..<nums.count { | |
for j in 0..<i where dp[i] <= dp[j] && nums[j] < nums[i] { | |
dp[i] = dp[j] + 1 | |
} | |
} |
This file contains hidden or 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
import Foundation | |
import Vapor | |
import OpenAPIRuntime | |
import OpenAPIVapor | |
struct GreetingService: APIProtocol { | |
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output { | |
let name = input.query.name ?? "Stranger" | |
let greeting = Components.Schemas.Greeting(message: "Hello, \(name)!") | |
return .ok(.init(body: .json(greeting))) |
This file contains hidden or 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
import Vapor | |
let app = Application() | |
try app.run() |
This file contains hidden or 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
openapi: "3.1.0" | |
info: | |
title: "App" | |
version: "1.0.0" | |
servers: | |
- url: "https://api.path.com/v1" | |
description: "Production Server" | |
- url: "https://localhost/v1" | |
description: "Internal staging server for testing" |
NewerOlder