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
sealed interface Data<T> { | |
record DataString(String value) implements Data<String> {} | |
static <T> T get(Data<T> data) { | |
// why I need to force the cast to T? | |
return (T) switch (data) { | |
case DataString(var value) -> value; | |
}; | |
} |
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.util.function.BiFunction; | |
import java.util.function.Function; | |
public interface Bug<T> { | |
<R> Bug<R> map(Function<? super T, ? extends R> mapper); | |
<R> Bug<R> ap(Bug<Function<? super T, ? extends R>> apply); | |
static <A, B, C> Function<BiFunction<A, B, C>, Bug<C>> compile(Bug<? extends A> fa, Bug<? extends B> fb) { |
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.util.function.Supplier; | |
public record Bug(int value) { | |
static void bug(Supplier<String> str) { | |
System.out.println(str.get()); | |
} | |
public Bug { | |
bug(() -> "hello"); |
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 static java.util.Objects.requireNonNull; | |
public class Builder { | |
public static void main(String[] args) { | |
User user = User.builder().id(1).name("toni").email("toni@home").build(); | |
System.out.println(user); | |
} | |
} |
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
//usr/bin/env jbang "$0" "$@" ; exit $? | |
//JAVA 21 | |
//JAVAC_OPTIONS --enable-preview -source 21 | |
//JAVA_OPTIONS --enable-preview | |
//DEPS com.github.tonivade:purefun-typeclasses:5.0 | |
//DEPS com.github.tonivade:purefun-instances:5.0 | |
//DEPS com.github.tonivade:purefun-transformer:5.0 |
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.util.function.Function; | |
import java.util.function.Supplier; | |
public class Main { | |
public static void main(String args[]) { | |
var some = new Some<>("hello"); | |
var result = some.map(String::toUpperCase); | |
System.out.println(result.orElse("")); |
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
/* | |
* Copyright (c) 2018-2019, Antonio Gabriel Muñoz Conejo <antoniogmc at gmail dot com> | |
* Distributed under the terms of the MIT License | |
*/ | |
package com.github.tonivade.purefun.zio; | |
import static com.github.tonivade.purefun.monad.Console.println; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import java.io.BufferedReader; |
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 static com.github.tonivade.purefun.data.Sequence.listOf; | |
import static java.util.Objects.requireNonNull; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import org.junit.jupiter.api.Test; | |
import com.github.tonivade.purefun.Higher1; | |
import com.github.tonivade.purefun.Kind; | |
import com.github.tonivade.purefun.Tuple2; | |
import com.github.tonivade.purefun.Unit; |