Coder Social home page Coder Social logo

fig's Introduction

Fig Build Status Documentation

Java elegant supplement

Java 8 delivered lambda expressions, but without the enhancement of basic libraries like List, Map, String, which makes lambda expression still not delightful.

Borrowered from Ruby basic library, Fig intends to supply the missing.

Quick Scan

Elegant alternative to List: Seq

Seq<Integer> seq = Seq.of(1,2,3);
seq.shuffle(); // copy to a new seq and shuffle it
seq.shuffle$(); // shuffle the original seq
seq.forEach((value, idx) -> { // with index
    // (1, 0)  (2, 1)  (3, 2)
});
seq.forEachCons(2, (values)->{
    // [1,2]  [2, 3]
});

seq.join("-"); //"1-2-3"

seq.map(a -> a+ 1).distinct().reverse().join()

Elegant alternative to Map: Hash

Hash<Integer, Integer> hash = Hash.newHash();
hash.set(1, 2).set(2, 3).set(3, 3);
hash.containsAny((k, v)-> k+v == 5 ); //true
hash.keysOf(3); // [2, 3]

Elegant alternative to String: CharSeq

CharSeq str = CharSeq.of("a b c d e f g");
str.split(" ").join("-").capitalize(); //"A-b-c-d-e-f-g"
str.partition("d e").map(CharSeq::trim);  //["a b c", "d e", "f g"]

Full Javadoc

Include it

<dependency>
    <groupId>com.worksap</groupId>
    <artifactId>fig</artifactId>
    <version>0.1.0</version>
</dependency>

Concept

Not stream

Fig is different from Stream, and implemented without Stream. While, it is simpler concept -- supplement methods on basic library.

Stream has several characteristics:

  1. Trends to process each element independently
  2. Infinite that we can not get the size
  3. Designed for large data flow performance

Thus, Stream may not be able to support operations related with the size of it, nor operations involving multiple or even random elements.

Fig targets on "small data" operations within application logic, to provide simple & beautiful code writing about String, List, Map operation & transformation.

No utilities

In traditional Java way, we use a lot of utilities (StringUtils, FileUtils) for the missing methods in standard library. While in Fig, we make an object oriented and functional way to free you from tedious code.

Zero runtime dependency

Fig has no external runtime dependency except JDK 8.

Conventions

Fig uses conventions on method names similar with Ruby. If there is a pair of methods name, name$, method ends with $ means calling this method will change the object itself, while calling the other won't.

License

Apache License 2.0

Contribution

Feel free to submit issues & PRs

fig's People

Contributors

leonliuy avatar wangboxue avatar ronaldolee avatar

Watchers

James Cloos avatar Purgna avatar

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.