Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric kitasuna

  • Tokyo, Japan
View GitHub Profile
@kitasuna
kitasuna / package.json
Last active Oct 20, 2020
Some fun with fp-ts2's Reader monad
View package.json
{
"name": "reader-intro",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
@kitasuna
kitasuna / index.ts
Created Jul 30, 2020
Playing with Generators in TS
View index.ts
function f (str: string) {
return str + "!"
}
function* g(str: string) {
yield str.length > 0
return str + "!"
}
function* h(str: string) {
@kitasuna
kitasuna / index.ts
Last active Sep 21, 2019
Advent of Code 2018, Day 5, Part 1
View index.ts
import * as fs from 'fs'
const contents = fs.readFileSync('input', 'utf8')
const valuesReact = (x: string) => (y: string) => {
const del = Math.abs((x.charCodeAt(0) - y.charCodeAt(0)))
return del === 32
}
const fin = contents.split('').reduce((acc, curr) => {
@kitasuna
kitasuna / index.js
Created Sep 7, 2019
Nullary types in Sanctuary
View index.js
const $ = require('sanctuary-def')
const { create, env } = require('sanctuary')
const def = $.create({
checkTypes: true,
env: $.env
})
const MyBool = $.NullaryType
('dokidoki-types/MyBool')
@kitasuna
kitasuna / index.js
Created Aug 11, 2019
Custom types with custom function in Sanctuary
View index.js
const $ = require('sanctuary-def')
const { create, env } = require('sanctuary')
const def = $.create({
checkTypes: true,
env: $.env
})
const FirstType = $.NullaryType
('dokidoki-types/FirstType')
@kitasuna
kitasuna / index.ts
Created Jul 1, 2019
Trying out fp-ts ReaderT
View index.ts
import * as readerT from "fp-ts/lib/ReaderT"
import { future } from "fp-ts-fluture/lib/Future"
import { of, reject, FutureInstance as Future } from "fluture"
import { identity } from "fp-ts/lib/function";
type Env = {
locale: string
}
const env$: Env = {
@kitasuna
kitasuna / index.js
Created Mar 13, 2019
Defining custom functions in sanctuary
View index.js
const $ = require('sanctuary-def')
const def = $.create({
checkTypes: true,
env: $.env
})
const bangBang =
def ('bangBang')
({})
@kitasuna
kitasuna / 00.js
Last active Nov 5, 2018
Defining Custom Types in Sanctuary
View 00.js
const S = require('sanctuary')
const $ = require('sanctuary-def')
const x = 42
const s = "butter"
// this will work
const oops = x + s
// this will blow up
@kitasuna
kitasuna / index.ts
Created Mar 8, 2018
Different fluture patterns
View index.ts
import axios from 'axios'
import * as R from 'ramda'
import * as Future from 'fluture'
import { Promise } from 'es6-promise'
import { AxiosResponse, AxiosError } from "axios";
interface Post {
id: number;
userId?: number;
title: string;
You can’t perform that action at this time.