Skip to content

Instantly share code, notes, and snippets.

@gaku-sei
gaku-sei / main.rs
Created August 17, 2016 18:06
Sum and Product in Rust
use std::convert::From;
use std::ops::{Add, Mul};
trait Sumable<T> {
fn sum(&self) -> T;
}
trait Productable<T> {
fn product(&self) -> T;
}
@gaku-sei
gaku-sei / Main.elm
Last active October 4, 2016 08:07
Big list with request example
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App exposing (..)
import Json.Decode exposing (..)
import Http
import Task
type alias Photo =
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App exposing (..)
import Json.Decode exposing (..)
import Http
import Task
type alias Todo =
@gaku-sei
gaku-sei / Main.elm
Last active October 9, 2016 09:25
Huge todolist with inputs
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App exposing (..)
import Html.Lazy exposing (..)
import Json.Decode exposing (..)
import Http
import Task
@gaku-sei
gaku-sei / sum.swift
Last active November 22, 2016 22:25
protocol Zero {
static var zero: Self { get }
}
protocol Sumable {
static func +(lhs: Self, rhs: Self) -> Self
}
extension Int: Sumable {}
@gaku-sei
gaku-sei / Random.js
Last active April 7, 2017 06:27
Some fun with Effects in Purescript !
exports.random = Math.random;
type NewType<Name extends string, Type> = Type & {
readonly "": Type;
};
function to<T extends NewType<string, U>, U = T[""]>(x: U): T {
return x as T;
}
type Size = NewType<"Size", number>;
@gaku-sei
gaku-sei / coroutine.tsx
Created November 27, 2018 05:21
Simple Context.Provider coroutine
function coroutine<Props>(
generator: (props: Props) => IterableIterator<JSX.Element>
): React.ComponentType<Props> {
return (props: Props) => {
const iterator = generator(props);
const rec = (Component: JSX.Element, done: boolean): JSX.Element => {
if (!done) {
const { done, value } = iterator.next();
@gaku-sei
gaku-sei / types.re
Last active August 21, 2019 06:06
Some remarks on Reasonml "object" like types
/// Records
// Straigth forward, use this when an object remains in the BuckleScript realm
type record = { foo: int };
// Will _not_ compile to a JS object (at least, until some pr like https://github.com/BuckleScript/bucklescript/pull/3741 are merged)
let record: record = { foo: 42 };
/// OCaml objects
@gaku-sei
gaku-sei / Nonempty.re
Created September 2, 2019 01:58
Nonempty lists with clean syntax in Reason (requires Bucklescript 6.*)
type empty;
type nonempty;
type t(_, _) =
| []: t('a, empty)
| ::('a, t('a, _)): t('a, nonempty);
let rec fromList: ('a, list('a)) => t('a, nonempty) =
x =>