Skip to content

Instantly share code, notes, and snippets.

public class GenericReturnType {
public static void main(String[] args) {
// 引数の型は `Object` なので戻り値から型パラメータが推論される
Integer n = id(42);
String s = id("xyz");
System.out.println(n);
System.out.println(s);
}
func foo() -> Int { return 2 }
func foo() -> Float { return 3.0 }
let a: Int = foo()
let b: Float = foo()
print(a) // 2
print(b) // 3.0
import java.util.Arrays;
import java.util.List;
interface Integer {
int getValue();
}
final class ConcreteInteger implements Integer {
private final int value;
ConcreteInteger(int value) { this.value = value; }
print("Hello Swift!")
import java.util.*;
import java.io.PrintStream;
public class CollectionsPerformance {
public static void main(String[] args) {
final PrintStream out = System.out;
final int n = 100000;
final Integer x = 42;
extension Dictionary {
func filterMap<T>(_ transform: (Value) -> T?) -> [Key: T] {
var transformed = [Key:T]()
for entry in self {
if let newValue = transform(entry.value) {
transformed[entry.key] = newValue
}
}
return transformed
}
// Swift 2.2
import XCTest
import Foundation
import RealmSwift
private let n = 100000
private let numberOfLoops = 1000
class RealmPerformanceTest: XCTestCase {
func testIndexedFilterPerformance() {
print("Hello, WWDC!")
Hello love at first swipe.
Hello other side of the road.
Hello yogi on my wrist.
Hello driver, fast as you can.
Hello workout in my living room.
Hello every pitch, every highlight.
Hello self-combusting selfies.
Hello double tap heart.
Hello rain in five minutes.
# coding:utf-8
import tensorflow as tf
from random import choice
zun = -1.0
doko = 1.0
zun_length = 4
zundoko_length = zun_length + 1
@koher
koher / 1-throws-as-returning-a-result.md
Last active March 14, 2016 11:28
Proposal for error handling in Swift

throws as returning a Result

I think it would be great if throws -> Foo were a syntactic sugar of -> Result<Foo>. Without affecting existing codes, it makes it possible to go back and forth between Manual Propagation and Automatic Propagation seamlessly.

// I wish if the first `makeFoo` were
// a syntactic sugar of the second one
func makeFoo(x: Int) throws -> Foo {
  guard ... else {
 throw FooError()