Skip to content

Instantly share code, notes, and snippets.

View 7h3kk1d's full-sized avatar

Alexander Bandukwala 7h3kk1d

View GitHub Profile
Slack Variety Pack
Unfilter
Somebody's Gotta Win with Tara Palmeri
A Life Well Wasted
Behind The Tech with Kevin Scott
Self-hosted Web
The Tim Ferriss Show
Newton's Law
TED Radio Hour
Work, Life, and RV Podcast
@7h3kk1d
7h3kk1d / Table.java
Created July 17, 2024 19:02
Basic lambda implementation of a table/dataframe
package com.jnape.palatable.lambda;
import com.jnape.palatable.lambda.adt.hlist.HList;
import com.jnape.palatable.lambda.functions.builtin.fn3.ZipWith;
import com.jnape.palatable.lambda.monoid.builtin.Join;
import java.util.List;
import static com.jnape.palatable.lambda.adt.hlist.HList.nil;
@7h3kk1d
7h3kk1d / Dog.java
Created October 28, 2022 01:49
Monadic SQL Transactions
import java.sql.Date;
public record Dog(String name, Date birthdate) {}
@7h3kk1d
7h3kk1d / TransactionExample.java
Created October 26, 2022 14:28
Transactional Example
public class TransactionExample {
public static void main(String[] args) {
Transactor<IO<?>, Unit, String> transactor = new Transactor<>() {
@Override
public <A> IO<Either<String, A>> runTransactional(Transactional<IO<?>, String, Unit, A> transactional) {
Unit connection = UNIT;
return IO.io(() -> System.out.println("Starting Transaction"))
.discardL(transactional.run(connection)
.<IO<Either<String, A>>>coerce()
.flatMap(e -> e.match(s -> IO.io(() -> System.err.printf("Rolling back transaction due to %s%n", s)),
@7h3kk1d
7h3kk1d / Failable.java
Created July 22, 2022 22:23
Failable Monad
public sealed interface Failable<A> extends CoProduct2<List<String>, A, Failable<A>>, Monad<A, Failable<?>> {
@Override
default <B> Failable<B> flatMap(Fn1<? super A, ? extends Monad<B, Failable<?>>> fn1) {
return match(Failed::new, fn1.fmap(Monad::coerce));
}
@Override
default <B> Failable<B> pure(B b) {
return new Success<>(b);
}
@7h3kk1d
7h3kk1d / hkd_class.java
Last active July 17, 2022 20:22
Higher Kinded Data Pattern in Lambda
public class Person<F extends MonadRec<?, F>> {
MonadRec<Integer, F> age;
MonadRec<String, F> name;
public Person(MonadRec<Integer, F> age, MonadRec<String, F> name) {
this.age = age;
this.name = name;
}
public static Person<ReaderT<String, Either<String, ?>, ?>> personValidation() {
@7h3kk1d
7h3kk1d / echo.java
Created November 1, 2021 17:19
An example of an algorithm being parametric in it's monad to be used with or without IO
package com.thekkid.ninetyninelambdas.problems;
import com.jnape.palatable.lambda.adt.Unit;
import com.jnape.palatable.lambda.functions.builtin.fn2.ToCollection;
import com.jnape.palatable.lambda.functor.builtin.State;
import com.jnape.palatable.lambda.io.IO;
import com.jnape.palatable.lambda.monad.MonadRec;
import java.util.ArrayList;
import java.util.Collections;
@7h3kk1d
7h3kk1d / bool
Created April 8, 2020 00:40
bool.java
public abstract class Bool extends Number implements CoProduct2<Bool.False, Bool.True, Bool> {
@Override
public byte byteValue() {
return match(constantly((byte) 0),
constantly((byte) 1));
}
@Override
public short shortValue() {
return byteValue();
Prelude> [\x -> x + 1, \x -> x -1] <*> [1,2]
[2,3,0,1]
Prelude> [1,2] >>= \y -> [y+1, y-1]
[2,0,3,1]
import random
while True:
a = [random.randint(1, 6), random.randint(1, 6), random.randint(1, 6), random.randint(1, 6)]
print(a)
if len(set(a)) == 1:
break