Skip to content

Instantly share code, notes, and snippets.

@forketyfork
forketyfork / Integer2.java
Created May 11, 2021 06:52
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
public class Integer implements Monoid<Integer> {
public Integer empty() {
return 1;
}
public Integer append(Integer other) {
return this * other;
}
@forketyfork
forketyfork / Integer.java
Created May 11, 2021 06:51
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
public class Integer implements Monoid<Integer> {
public Integer empty() {
return 0;
}
public Integer append(Integer other) {
return this + other;
}
@forketyfork
forketyfork / Concat.java
Created May 11, 2021 06:49
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
public <T extends Monoid<T>> Optional<T> concat(List<T> monoids) {
return monoids.stream()
reduce(Monoid::append);
}
@forketyfork
forketyfork / String.java
Created May 11, 2021 06:47
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
public class String implements Monoid<String> {
@Override
public String empty() {
return "";
}
@Override
public String append(@NonNull String other) {
return this + other;
@forketyfork
forketyfork / Monoid.java
Created May 11, 2021 06:47
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
interface Monoid<T extends Monoid<T>> {
T empty();
T append(T other);
}
@forketyfork
forketyfork / MyService.java
Last active May 11, 2021 07:22
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
interface MyService {
void doWork();
}
class MyServiceImpl implements MyService {
@Override
public void doWork() {
$ docker ps --all --filter label=type=secondary
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a2b8a308cf5 mybusybox "sh" 5 minutes ago Exited (0) 5 minutes ago mybusybox-container-3
8bd0108e3fa8 mybusybox "sh" 5 minutes ago Exited (0) 5 minutes ago mybusybox-container-2
// setting the latch to 1
CountDownLatch transactionLatch = new CountDownLatch(1);
// adding a node as the first node of the route
AdviceWithRouteBuilder.adviceWith(camelContext, "queueRoute", context ->
context.weaveAddFirst().process(exchange ->
// adding transaction synchronization
TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronizationAdapter() {
@Override
TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
// do something after transaction commit
}
}))
AdviceWithRouteBuilder.adviceWith(camelContext, "queueRoute", context ->
context.weaveAddFirst().process(exchange -> {
// do something before exchange processing
}
);