Coder Social home page Coder Social logo

motif's Introduction

motif's People

Contributors

runeflobakk avatar sindrebn avatar

Stargazers

Henning Jensen avatar Frode Nerbråten avatar Erlend Oftedal avatar Ståle Pettersen avatar  avatar Joel Chelliah avatar

Watchers

 avatar SwhGo_oN avatar

motif's Issues

Force evaluation of Elements<T>

For expensive map and/or filters, it may be convenient to force evaluation and still return Elements for further mapping/filtering/other operations. This is opposed to calling collect() and then wrap the returned List in another Iterate.on(..).

A Comparator API

It's already possible to create Comparators using a Fn<?, ? extends Comparable<?>>. It should return an interface (say EnhancedComparator<T> or similar) with methods to create modifications based on the original Comparator.

Suggestion:

interface EnhancedComparator<T> extends Comparator<T> {
   EnhancedComparator<T> descending();
   EnhancedComparator<T> nullsFirst(); //nullsafe comparator
   EnhancedComparator<T> nullsLast();  //nullsafe comparator
}

Strings.reversed

A Fn which takes a String and returns it with its characters in reversed order

Base.equalTo(Fn0)

equalTo-predicate which resolves its operand on each application. Typically used to check for equivalence on some independently continuously changing value, e.g. the system clock.

Remove redundant NullIfArgIsNull and DefaultIfArgIsNull

The abstract classes NullIfArgIsNull and DefaultIfArgIsNull are not needed anymore, and can be removed. Existing usage can be replaced with composition using Base.when(..) instead of the slightly awkward inheritance based approach with those classes.

Make Motif Java 6 compatible

The original reason for Motif being compiled for Java 7 is the @SafeVarargs annotation introduced in Java 7. It has come to my attention that using the @SafeVarargs annotation, even when it is included in the binary with RetentionPolicy.RUNTIME, will not break when executed on a platform without the annotation (i.e. Java 6, and Java >= 5.0u6) as per the Java Language Spec

http://stackoverflow.com/questions/3567413/why-doesnt-a-missing-annotation-cause-a-classnotfoundexception-at-runtime

http://bugs.sun.com/view_bug.do?bug_id=6322301

Strings.indexOf(..): Fn<String, Integer>

Map a string to the index of the first appearing character, much the same way as java.lang.String.indexOf.

Should probably return null instead of -1 for no matches, in order to correctly map an Optional to None.

May also include a variant to find the beginning index of a substring? Strings.indexOf(String)

Reflect.name does not work on Classes

class Class does not implement Member. Thus Reflect.name only works with methods and fields.

Not really a bug, but definitely a missing feature which was expected to be there.

Strings.allBetween

Fn<String, Iterable<String>> which puts all substrings it can find between two given strings in an iterable.

Iterate.newInstance(Iterable) should not call iterator().hasNext()

For Iterables which consumes its contents, typically Iterable views of streams, this optimization may yields some surprises, as one element will be consumed during the check for emptiness.

E.g.

public final class ZipEntries implements Iterable<ZipEntry> {
    private final ZipInputStream zip;
    public ZipEntries(ZipInputStream zip) { this.zip = zip; }

    @Override public Iterator<ZipEntry> iterator() {
        return new SimpleIterator<ZipEntry>() {
            @Override protected Optional<? extends ZipEntry> nextIfAvailable() {
                try {
                             return optional(zip.getNextEntry());
                        } catch (IOException e) {
                           throw new RuntimeException(e.getMessage(), e);
                       }
                }};
    }
}

will skip over the first element if wrapped with Iterate.on(new ZipEntries(..))

Make Motif Java 6 compatible

It has come to my attention that Motif may use the @SafeVarargs annotation and still be compatible with Java 6, as the Java Language Specification states that an annotation compiled into the binary (RetentionPolicy.{RUNTIME, CLASS}) does actually not need to be available at runtime.

So Motif can be developed on Java 7 and compiled for Java 6 as long no Java 7-specific API is used. However, using @SafeVarargs will not prevent the use of Motif on Java 6.

http://stackoverflow.com/questions/3567413/why-doesnt-a-missing-annotation-cause-a-classnotfoundexception-at-runtime

http://mojo.codehaus.org/animal-sniffer-maven-plugin/examples/generating-java-signatures.html

More effective handling of iterating Strings and arrays

Iterate.on(String) invokes toCharArray which effectively duplicates the characters of the given string. This is unnecessary.

Implement an abstract Iterator to better support iterating elements given a start and end index. Also provide implementation for iterating characters of a String, and most common arrays of primitives (byte, char, int).

Reflect.name

A Fn to get the name of a java.lang.reflect.Member (class, method, field, etc)

Optional.None should implement equals() & hashCode()

In most circumstances, None is a true singleton, effectively enforced through standard Java visibility rules. Even so, using Optional with libraries/frameworks which relies on serialization (e.g. Hazelcast, Wicket, etc), will manage to deserialize to a new None-instance, and thus none.equals(anotherNone) will return false.

Change name of abstract method in Do<V>

The method to override in Do<V> should be renamed to be able to have classes implementing both Fn<I,O> and Do<V>.

Make no.motif.f.base.Throw<I1, I2, O> implement Do<I1> when this is done.

Need a more generic term for Optional.split(..)

The method-name "split" on Optional<V> and A<V> is somewhat awkward since it hints about how a value is transformed into several values. The passed Fn should describe how it will be done, e.g. splittingOn(','). Using this as an exsample, possible names can be:

  • the("a,b,c").explode(splittingOn(','))
  • the("a,b,c").toElements(splittingOn(','))
  • the("a,b,c").dissect(splittingOn(','))

YieldsJavaCollection.mapBy(Fn<T,K>)

New "bridge" back to Java collections which are able to on each element, compute a key for the element, and put the resulting key and element as key and value into a map, which is returned. The mapBy method must include documentation that the Fn should compute unique keys for each element, and what the behavior will be if that is not the case.

Add upcast operation to Optional

It is sometimes useful to upcast an Optional to a less specific type

Say if your method is declared to return an Optional<A>, and your method prepares a value v of type B extends A. The statement return optional(v) will not compile, since the type is inferred to be Optional<B>

Candidate method names:

  • .as(Class<N super V>): Optional<N>
  • .upcastTo(Class<N super V>): Optional<N>

Strings.between, Strings.after, Strings.before

Substring operations:

  • extract string between two other strings
  • the string after the first occurence of a given string
  • the string before the first occurence of a given string.

This depends on #10 being done first.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.