Time consuming hashCode calculation (of immutable objects)?
These objects are used in a HashMap?
No problem!
class MyClass {
// may also be Lazy.of(this::timeConsumingOperation)
Time consuming hashCode calculation (of immutable objects)?
These objects are used in a HashMap?
No problem!
class MyClass {
// may also be Lazy.of(this::timeConsumingOperation)
public interface RedBlackTree<T> { | |
static <T extends Comparable<T>> EmptyNode<T> empty() { | |
// HERE: | |
return new EmptyNode<>(T::compareTo); | |
} | |
class EmptyNode<T> implements RedBlackTree<T> { | |
EmptyNode(Comparator<? super T> comparator) { |
class FunctionalQueueImpl<T> implements Queue<T> { | |
// ... | |
@Override | |
public <C> Map<C, Queue<T>> groupBy(Function<? super T, ? extends C> classifier) { | |
return foldLeft(HashMap.empty(), (map, t) -> { | |
final C key = classifier.apply(t); | |
final Queue<T> queue = map.getOption(key).orElse(Queue.empty()); | |
return map.put(key, queue.enqueue(t)); |
package models | |
import play.api.mvc.PathBindable | |
object Account extends Enumeration { | |
val Company, Sales = Value // create enumerated values | |
// url path binding (routes) | |
implicit def bindableAccount = new PathBindable[Account.Value] { |
package models | |
object Account extends BindableEnum { | |
val Company, Sales = Value // create enumerated values | |
} |
/** | |
* PLEASE AVOID THIS IMPLEMENTATION BECAUSE OF... | |
* - a cache should be garbage collectable (on low memory) | |
* (see Soft Reference, Weak Reference etc.) | |
* - a cache should be thread safe (this is not) | |
*/ | |
class CachedLdapPermissionResolver extends LdapPermissionResolver { | |
private static final long MAX_TIME = 1000 * 60 * 10; // = 10 min. |
import javaslang.Lazy; | |
import javaslang.Value; | |
import javaslang.control.Try; | |
class PeekSomeValues {{ | |
Seq<Value<String>> values = List.of( | |
// a lazy value | |
Lazy.of(() -> "test"), |
/* JAVA */ | |
public class SampleExtensions { | |
public static String sort(String s) { | |
final char[] arr = s.toCharArray(); | |
java.util.Arrays.sort(arr); | |
return String.valueOf(arr); | |
} |
/* / \____ _ _ ____ ______ / \ ____ __ _ _____ | |
* / / \/ \ / \/ \ / /\__\/ // \/ \ / / _ \ Javaslang | |
* _/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \__/ / Copyright 2014-now Daniel Dietrich | |
* /___/\_/ \_/\____/\_/ \_/\__\/__/___\_/ \_// \__/_____/ Licensed under the Apache License, Version 2.0 | |
*/ | |
package javaslang.concurrent; | |
import javaslang.collection.Queue; | |
import javaslang.control.None; | |
import javaslang.control.Option; |
Calling factory methods of same name for single and multiple elements may raise ambiguities problems. This is the case for the actual java.util.stream.Stream#of(T) and #of(T...)
API.
These are the relevant cases (compiling with -Xlint:all -Werror
):
1. It is hard to create a Stream<T[]>
Stream.of(arrayOfObj)
calls Stream.of(T...)
instead of Stream.of(T)
.