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
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; |
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
import java.sql.Date; | |
public record Dog(String name, Date birthdate) {} |
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
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)), |
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
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); | |
} |
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
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() { |
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
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; |
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
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(); |
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
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] |
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
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 |
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
/* 11/27/2017 - Tweaked for a page redesign. | |
* 1/6/2018 - Handle videos in book bundle. | |
*/ | |
var pattern = /(MOBI|EPUB|PDF( ?\(H.\))?|CBZ)$/i; | |
var pattern2 = /(Download)$/; | |
var nodes = document.getElementsByTagName('a'); | |
var downloadCmd = ''; | |
for (i in nodes) { | |
var a = nodes[i]; | |
if (a && a.text && pattern.test(a.text.trim())) { |
NewerOlder