Skip to content

Instantly share code, notes, and snippets.

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()
@koher
koher / something-is-wrong-in-swifts-type-system.md
Last active December 6, 2015 14:15
Something seems to be wrong in Swift's type system.

That was my misunderstanding especially about subtyping of value types.

@koher
koher / TreeMapGetGetsException.java
Created September 29, 2015 22:50
TreeMap#get gets ClassCastException
import java.util.*;
Map<String, Integer> map = new TreeMap();
map.put("abc", 123);
map.put("def", 456);
map.put("ghi", 789);
map.get("abc");
map.get(123); // java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer