After reading Make Everything The Same post by Sandi Metz I've started thinking about one of my own experiences with software design. During the evolution of one system I've faced a challenge of extending billing subsystem. I've actually spent couple of days thinking about the problem and this process in foresight seems very similar to one described be Sandi. At first everything seemed clear about problem, but I hated conditionals that have sprung into life. This raise of conditionals seemed both inevitable, but somehow artificially inflicted.
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
Map<String, Integer> map = // ... | |
int limit = 50; | |
PriorityQueue<Map.Entry<String, Intger>> queue = new PriorityQueue<>(limit, Comparator.comparing(Map.Entry::getValue).reversed()); | |
for (var entry: map.entrySet()) { | |
if (queue.size() == limit) { | |
queue.remove(); // Remove MAXIMAL element | |
} | |
queue.add(entry); | |
} |
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.github.sviperll; | |
import com.github.sviperll.exception.ExceptionfulConsumer; | |
import com.github.sviperll.exception.ExceptionfulFunction; | |
import com.github.sviperll.exception.ExceptionfulRunnable; | |
import com.github.sviperll.exception.ExceptionfulSupplier; | |
import javax.annotation.ParametersAreNonnullByDefault; | |
import java.util.Optional; | |
import java.util.function.Function; |
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
/** | |
* | |
* @author Victor Nazarov <[email protected]> | |
*/ | |
public class GADT<T> extends GADTBase<GADT<Integer>, GADT<Boolean>, GADT<T>> { | |
public static GADT<Integer> literal(int i) { | |
return new GADT<Integer>(GADTBase.<GADT<Integer>, GADT<Boolean>, GADT<Integer>>_literal(i)); | |
} |
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
class List implements Monad { | |
(:), nil, (++), null public; | |
(:), nil constructor; | |
(:) :: forall a. a -> this a -> this a; | |
nil :: forall a. this a; | |
(++) :: forall a. List a -> List a -> List a; | |
(x:?xs) ++ ys = x : (xs ++ ys); | |
nil? ++ ys = ys; |
I have been thinking a lot about implementing functional lazy language targeting JVM with syntax like:
class Maybe a = Just a | Nothing
implements Monad, Eq when a implements Eq, Ord when a implements Ord
where {
derive Ord;
derive Eq;
override {