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
package main | |
import "fmt" | |
type Person struct { | |
name string | |
age int | |
} | |
func (p Person) greet() { |
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
package main | |
import ( | |
"log" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte(` |
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
extension IntegerType { | |
var isZorome: Bool { | |
let characters = "\(self)".characters | |
guard characters.count < 2 else { | |
return false | |
} |
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
func isZorome(number:Int) -> Bool { | |
let numString = String(number) | |
guard numString.characters.count > 1, let first = numString.characters.first else { | |
return false | |
} | |
let bools = numString.characters.map { $0 == first }.reduce(true) { (a, b) -> Bool in | |
a&&b |
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
public mutating func next() -> Element? { | |
guard let b = base.next() else { return nil } | |
defer { count += 1 } | |
return (index: count, element: b) | |
} |
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
typealias PaymentType = (Bool, Bool, Bool) | |
func getPayAmountEasySwitch(payment: PaymentType) -> Double { | |
switch (payment.0, payment.1, payment.2) { | |
case (true, _, _): | |
return 0.0 | |
case (_, true, _): | |
return 1.0 | |
case (_, _, true): |
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
func DebugLog(@autoclosure condition: () -> Bool = true, _ message: String = "", function: StaticString = __FUNCTION__, file: StaticString = __FILE__, line: UInt = __LINE__) { | |
#if DEBUG | |
if let fileName = NSURL(string: String(file))?.lastPathComponent { | |
print("time: \(NSDate()), message: \(message), function: \(function), file: \(fileName), line: \(line)") | |
} else { | |
print("time: \(NSDate()), message: \(message), function: \(function), file: \(file), line: \(line)") | |
} | |
assert(condition, message, file: file, line: line) |
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
enum Option { | |
case Regular(MoreOption) | |
case Irregular(MoreOption) | |
} | |
enum MoreOption { | |
case One, Two, Three | |
} | |
let os1 = Option.Regular(.One) | |
let os2 = Option.Regular(.Two) |
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
typealias Closure = (Int,Int) -> Int | |
let addClosure = { (a:Int, b:Int) -> Int in | |
return a+b | |
} | |
let multipleClosure = { (a:Int, b:Int) -> Int in | |
return a*b | |
} |
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
protocol Foo { | |
func hoge() -> Void | |
} | |
extension Foo { | |
func hoge() -> Void { | |
print("hoge") | |
} | |
func hoge2() -> Void { |