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
// requires TypeScript 2.1 or higher | |
export abstract class Lens<T, U> { | |
abstract get: (obj: T) => U; | |
abstract set: (value: U) => (obj: T) => T; | |
then = <V>(lens: Lens<U, V>) => new ComposedLens(this, lens); | |
thenKey = <L extends keyof U>(key: L): Lens<T, U[L]> => this.then(new ObjectLens<U, L>(key)); | |
modify = (f: (value: U) => U) => (obj: T) => this.set(f(this.get(obj)))(obj); | |
} | |
export class IdLens<T> extends Lens<T, T> { |
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
/* | |
Simple wrapper for SQLite3 | |
This code is Public Domain | |
**CAUTION** | |
1. No Warrantry | |
2. This code is *NOT* safe against SQL Injection. | |
3. This code can *NOT* handle BLOB or TEXT including '\0'. | |
4. You should *NOT* use this for production. |
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
/** | |
* Priority Queue for JavaScript | |
* | |
* simple implementation of priority queue with heap on javascript. | |
* | |
*/ | |
var PriorityQueue = function(cmp){ | |
this.heap = []; | |
this.cmp = (cmp == null) ? PriorityQueue.CMP : cmp; |
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
# ~*~ coding:utf-8 ~*~ | |
""" | |
数学でよく使う、掛け算記号の省略をやってみた | |
""" | |
def _(method): | |
def __(self, *args, **kw): | |
r = getattr(float, method)(self, *args, **kw) | |
return Float2(r) if isinstance(r, float) else r |
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
# ~*~ coding:utf-8 ~*~ | |
""" | |
============================================= | |
Support Increment and Decrement on Python | |
============================================= | |
>>> import inc_dec | |
>>> i = int(1) | |
>>> ++i | |
>>> print i |