Giter Site home page Giter Site logo

andyglick / emaze-dysfunctional Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cybazegroup/dysfunctional

0.0 2.0 0.0 3.49 MB

An extensive library for Java, providing functional programming features and promoting lazy evaluation wherever possible.

Home Page: http://emaze.github.io/emaze-dysfunctional

License: BSD 3-Clause "New" or "Revised" License

Java 100.00%

emaze-dysfunctional's Introduction

Changes

8.1.0

Additions

Introduced Collecting façade to support additional collectors.

  • Collecting.flat can be used to flat a Stream of Iterables, as an example:
Stream.of(Arrays.asList(1, 2, 3), Arrays.asList(4, 5)).collect(Collecting.flat()); // yields [1, 2, 3, 4, 5]
  • Collecting.reverse useful to invert the order of a finite stream.
Stream.of(1, 2, 3).collect(Collecting.reverse()); // yields [3, 2, 1]

Introduced Strategies façade with the following methods (⚠️ still to test!):

  • Function<T, R> firstMatch(Clause<T, R>... clauses) to apply the first clause matching a condition
  • Function<T, Optional<R>> maybeFirstMatch(Clause<T, R>... clauses) to apply optionally the first clause matching a condition
  • Function<T, List<R>> allMatches(Clause<T, R>... clauses) to apply all clauses matching a condition
  • also for binary functions

Added methods to Maps class to transform all keys and/or all values of the passed map, given a mapper function:

  • Map<W, V> mapKeys(Map<K, V> input, Function<K, W> keysMapper) to transform all keys of the passed map applying the passed mapper function
  • Map<W, V> mapKeys(Map<K, V> input, Function<K, W> keysMapper, BinaryOperator<V> valueMerger) to transform all keys of the passed map applying the passed mapper function. If the key is already present into the map, the passed value merger is applied to the value
  • Map<K, W> mapValues(Map<K, V> input, Function<V, W> valuesMapper) to transform all values of the passed map applying the passed mapper function
  • Map<KK, VV> mapKeysAndValues(Map<K, V> input, Function<K, KK> keysMapper, Function<V, VV> valuesMapper) to transform all keys and all values of the passed map applying the passed mapper functions
  • Map<KK, VV> mapKeysAndValues(Map<K, V> input, Function<K, KK> keysMapper, Function<V, VV> valuesMapper, BinaryOperator<VV> valueMerger) to transform all keys and all values of the passed map applying the passed mapper functions. If the key is already present into the map, the passed value merger is applied to the value

Refactors

Some better names:

  • renamed Multiplexing.batch in unchain (BatchingIterator -> UnchainIterator)
  • renamed Multiplexing.unchain in unchainShortest (UnchainIterator -> UnchainShortestIterator)
  • renamed Multiplexing.unchainWithExactChannelSize in unchainLongest (UnchainWithExactChannelSizeIterator -> UnchainLongestIterator)

Multiplexing.flatten and chain accepts varargs.

8.0

Additions

Introduced the Sequences façade, in order to simplify the usage of sequential streams. A Sequence has the following additional methods:

  • Consumers: toList, toSet, toMap, first, maybeFirst, one, maybeOne, last, maybeLast, nth, maybeNth, at, maybeAt
  • Filtering: take, takeLast, takeAtMostLast, takeWhile, drop, dropWhile, slice, distinctBy
  • Multiplexing: chain
  • Applications: tap

Added the following new methods:

  • Optional<LT> Either::left() method to get the left part of the Either
  • Function<Either<LT, RT>, Either<LR, RR>> Eithers::lift(Function<LT, LR> left, Function<RT, RR> right) to lift functions working on the components of an Either into a single function working on either
  • Function<Box<T>, Box<R>> Boxes::lift(Function<T, R> function) to lift a function to another working on box values
  • Maybe<T> Maybes::toMaybe(Optional<T> optional) to convert an Optional to a Maybe
  • Pair<T2, T1> Pair::flip()
  • Triple<T3, T2, T1> Triple::flip()
  • Triple<T2, T3, T1> Triple::rotateLeft()
  • Triple<T3, T1, T2> Triple::rotateRight()

Refactors

Replaced functional interfaces with built-in ones in package java.util.function:

  • Delegate -> Function
  • BinaryDelegate -> BiFunction
  • Provider -> Supplier
  • Predicate -> Predicate
  • BinaryPredicate -> BiPredicate
  • Action -> Consumer
  • BinaryAction -> BiConsumer
  • Proposition -> BooleanSupplier

Used java.util.Optional instead of Maybe.

Uniformed named with standard library:

  • Maybe.fmap -> Maybe.map
  • Maybe.value -> Maybe.get
  • Maybe.hasValue -> Maybe.isPresent
  • Box.fmap -> Box.map
  • Box.hasContent -> Box.isPresent
  • Either.fmap -> Either.map
  • Either.maybe -> Either.right
  • Pair.fmap -> Pair.map
  • Triple.fmap -> Triple.map
  • TernaryDelegate -> TriFunction
  • TernaryPredicate -> TriPredicate

Removed useless functors:

  • Identity -> use Function.identity() or x -> x
  • DropMaybe -> use Maybes::drop
  • EitherToMaybe -> use Eithers::right
  • PureMaybe -> use Optional::of
  • LiftMaybe -> use Optional::ofNullable
  • PureEither -> use Either::right
  • PureBox -> use Box::of
  • MaybeRight -> use Eithers::right
  • MaybeOrElse -> use lambda
  • MaybeLeft -> use Either::left
  • MaybeIteratorTransformer -> use MaybeIterator::new
  • IsNothing -> use Maybes::isEmpty
  • IsJust -> use Optional::isPresent
  • FromJust -> use Optional::get
  • FmapMaybe -> invoke Maybes.lift
  • FMapBox -> invoke Boxes.lift
  • FlipEither -> use Either::flip
  • FlipPair -> use Pair::flip
  • FlipTriple -> use Triple::flip
  • PairFirst -> use Pair::first
  • PairSecond -> use Pair::second
  • TripleFirst -> use Triple::first
  • TripleSecond -> use Triple::second
  • TripleThird -> use Triple::third
  • TripleRotateLeft -> use Triple::rotateLeft
  • TripleRotateRight -> use Triple::rotateRight
  • Max -> use BinaryOperator.maxBy
  • Min -> use BinaryOperator.minBy
  • Negator -> invoke predicate.negate()
  • Equals -> invoke Predicate.isEqual()
  • NotEquals -> invoke Predicate.isEqual().negate()
  • HasNext -> use Iterator::hasNext
  • IteratorPlucker -> use Iterable::iterator
  • ClassPlucker -> use Object::getClass

emaze-dysfunctional's People

Contributors

aljas avatar davidesalvador avatar edmcbane avatar gmasotti avatar grogdunn avatar labes avatar rferranti avatar

Watchers

 avatar  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.