Skip to content

Instantly share code, notes, and snippets.

View effe-megna's full-sized avatar
🎮

Francesco Megna effe-megna

🎮
  • Bologna
View GitHub Profile
interface Functions {
logout: (input: LogoutParams) => Promise<unknown>
userDetails: (input: UserDetailsParams) => Promise<unknown>
}
interface State {
user: unknown
}
interface LogoutParams {}
@effe-megna
effe-megna / These.elm
Last active May 8, 2020 15:25
These monad implemented in Elm
type These e a
= Both ( e, a )
| Left e
| Right a
map : (a -> b) -> These e a -> These e b
map f t =
bimap ( identity, f ) t
@effe-megna
effe-megna / queryBuilderTS.ts
Created March 2, 2020 17:13
SQL QueryBuilder type-safe, tiny poc
interface QbWithSelection <T extends Record<string, any> = never, Return = T> {
where: (condition: Partial<T>) => QueryBuilder<T, Return>
join: <NT extends Record<string, any>>(tableName: string) => QueryBuilder<T & NT, Return>
limit: (n: number) => QueryBuilder<T, Return>
offset: (n: number) => QueryBuilder<T, Return>
orderBy: <K extends keyof T>(columns: Array<K>, by: "ASC" | "DESC") => QueryBuilder<T, Return>
@effe-megna
effe-megna / Try.ts
Last active February 3, 2020 21:37
Try DataType for typescript, encoded as a class for Fluent API usage. (unsafe by spec :trollface:)
type TryADT <E, A> =
| { readonly _tag: "success", readonly success: A }
| { readonly _tag: "failure", readonly failure: E }
const success = <E, A>(successValue: A): TryADT<E, A> => ({ _tag: "success", success: successValue })
const failure = <E, A>(failureValue: E): TryADT<E, A> => ({ _tag: "failure", failure: failureValue })
class Try<E = never, A = never> {
internalValue!: TryADT<E, A>
import { Reader } from 'fp-ts/lib/Reader'
import { Monad3 } from 'fp-ts/lib/Monad'
import * as RD from "@devexperts/remote-data-ts"
import * as T from "fp-ts/lib/Task"
import { monadTaskRemoteData, TaskRemoteData, TRD } from "./TaskRemoteData"
import { pipe, pipeable } from "fp-ts/lib/pipeable"
import { sequenceT } from 'fp-ts/lib/Apply'
declare module 'fp-ts/lib/HKT' {
interface URItoKind3<R, E, A> {
@effe-megna
effe-megna / ReaderRemoteData.ts
Created November 4, 2019 11:58
monad ReaderRemoteData
import { Reader } from 'fp-ts/lib/Reader'
import { Monad3 } from 'fp-ts/lib/Monad'
import * as RD from "@devexperts/remote-data-ts"
import { getReaderM } from 'fp-ts/lib/ReaderT'
import { pipeable } from "fp-ts/lib/pipeable"
declare module 'fp-ts/lib/HKT' {
interface URItoKind3<R, E, A> {
ReaderRemoteData: ReaderRemoteData<R, E, A>
}
@effe-megna
effe-megna / TaskRemoteData.ts
Created November 4, 2019 11:57
monad TaskRemoteData
import { Monad2 } from 'fp-ts/lib/Monad'
import * as RD from "@devexperts/remote-data-ts"
import * as T from "fp-ts/lib/Task"
import * as TE from "fp-ts/lib/TaskEither"
import * as E from "fp-ts/lib/Either"
import { pipe, pipeable } from "fp-ts/lib/pipeable"
import { sequenceT } from 'fp-ts/lib/Apply'
declare module 'fp-ts/lib/HKT' {
interface URItoKind2<E, A> {
@effe-megna
effe-megna / RemoteData.kt
Last active October 21, 2019 20:42
Port of RemoteData to Kotlin
/**
*
* Port of [RemoteData](https://github.com/devexperts/remote-data-ts/blob/master/src/remote-data.ts)
*
* Represents a value of one of four possible types (a disjoint union)
* An instance of [RemoteData] is either an instance of [Initial], [Pending], [Failure] or [Success]
*
* A common use of [RemoteData] is as an alternative to [Either] or [Option] supporting initial and pending states
*
* Note: [Initial], [Pending] and [Failure] are commonly called "Left" part.
package com.bepower.becharge.ui
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
@effe-megna
effe-megna / someInjection.js
Created April 30, 2019 01:02
Some Injection
function getInstanceMethodNames (obj) {
return Object
.getOwnPropertyNames (Object.getPrototypeOf (obj))
.filter(name => (name !== 'constructor' && typeof obj[name] === 'function'));
}
function getInstanceStaticMethodNames (Class) {
return Object.getOwnPropertyNames(Class)
.filter(prop => typeof Class[prop] === "function");
}