Skip to content

Instantly share code, notes, and snippets.

View stefanofago73's full-sized avatar
💭
Software Designer, I like to build software, a little tormented soul

Stefano Fago stefanofago73

💭
Software Designer, I like to build software, a little tormented soul
View GitHub Profile
package it.fago.experiment.autocloseable.dirty;
import java.util.function.BiFunction;
import java.util.function.Consumer;
public class AutoCloser{
public static final <S> AutoCloseable autoclose(S element, Consumer<S> elementInvocation) {
return ((BiFunction<S, Consumer<S>, AutoCloseable>) (subject, callback) -> () -> callback.accept(subject)).apply(element, elementInvocation);
}
import static it.fago.experiments.EderChallenge.Operation.from;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class EderChallenge {
import static java.util.stream.Collectors.toList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
public interface Initializer<R> {
<?php declare(strict_types = 1);
/**
* NOTE:
*
* This example is for that legacy code where more error conditions
* are in sequence... Using exceptions, we are creating a control flow
* policy where every exception is an exit from actual flow.
* When not possible to refactor to FP or before using Try-Monad we can
* simulate monoid-al behaviour with an accumulator...
<?php declare(strict_types = 1);
/**
* NOTE:
*
* This example is for that legacy code where it's possible to
* refactor a sequence of action using a custom DSL.
* When not possible to refactor to FP or before using Try-Monad we can
* simulate something like a functor...
import java.util.List;
import static java.util.stream.Collectors.toList;
class Command {
}
interface CommandHandler {
public Result handle(Command cmd);
}
import static it.fago.loggerstein.Loggerstein.$;
import static it.fago.loggerstein.Loggerstein.lazy;
import static it.fago.loggerstein.Loggerstein.logWith;
import static it.fago.loggerstein.Loggerstein.STD_ERR;
import static it.fago.loggerstein.Loggerstein.STD_OUT;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.*;
<?php declare(strict_types = 1);
//-------------------------------------------
//
// FIRST NAMESPACES
//
//-------------------------------------------
namespace FST{
<?php declare(strict_types = 1);
class Logger
{
function info(string $msg):void{}
}
$logger = new Logger();
/**
//====================================
//
// MAIN TYPE
//
//====================================
public interface ComposingAutocloseable extends AutoCloseable
{