All Projects → pivovarit → Throwing Function

pivovarit / Throwing Function

Licence: apache-2.0
Checked Exceptions-enabled Java 8+ functional interfaces + adapters

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Throwing Function

Faux Pas
A library that simplifies error handling for Functional Programming in Java
Stars: ✭ 100 (-64.16%)
Mutual labels:  exception-handling, functional-programming
Swiftrex
Swift + Redux + (Combine|RxSwift|ReactiveSwift) -> SwiftRex
Stars: ✭ 267 (-4.3%)
Mutual labels:  functional-programming
05 Python Files
Python too supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files. The concept of file handling has stretched over various other languages, but the implementation is either complicated or lengthy, but like other concepts of Python, this concept here …
Stars: ✭ 163 (-41.58%)
Mutual labels:  exception-handling
Mu Scala
Mu is a purely functional library for building RPC endpoint based services with support for RPC and HTTP/2
Stars: ✭ 266 (-4.66%)
Mutual labels:  functional-programming
Java-Questions-and-Solutions
This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
Stars: ✭ 34 (-87.81%)
Mutual labels:  exception-handling
Sihl
A modular functional web framework
Stars: ✭ 267 (-4.3%)
Mutual labels:  functional-programming
ex
Exception net
Stars: ✭ 17 (-93.91%)
Mutual labels:  exception-handling
Write You A Haskell
Building a modern functional compiler from first principles. (http://dev.stephendiehl.com/fun/)
Stars: ✭ 3,064 (+998.21%)
Mutual labels:  functional-programming
Haskell Study Startup
Launch your own Haskell study group. Now.
Stars: ✭ 269 (-3.58%)
Mutual labels:  functional-programming
Pfps Shopping Cart
🛒 The Shopping Cart application developed in the book "Practical FP in Scala: A hands-on approach"
Stars: ✭ 262 (-6.09%)
Mutual labels:  functional-programming
Kotlinjetpackinaction
🔥🔥 Kotlin Jetpack zero to hero. 新手到高手
Stars: ✭ 264 (-5.38%)
Mutual labels:  functional-programming
bugsnag-symfony
Bugsnag notifier for the Symfony PHP framework. Monitor and report errors in your Symfony apps.
Stars: ✭ 42 (-84.95%)
Mutual labels:  exception-handling
Django Multiurl
Have you ever wanted multiple views to match to the same URL? Now you can.
Stars: ✭ 268 (-3.94%)
Mutual labels:  exception-handling
OOP-In-CPlusPlus
An Awesome Repository On Object Oriented Programming In C++ Language. Ideal For Computer Science Undergraduates, This Repository Holds All The Resources Created And Used By Me - Code & Theory For One To Master Object Oriented Programming. Filled With Theory Slides, Number Of Programs, Concept-Clearing Projects And Beautifully Explained, Well Doc…
Stars: ✭ 27 (-90.32%)
Mutual labels:  exception-handling
Golang Tutorials
Go Tutorials - Let's get our hands really dirty by writing a lot of Golang code
Stars: ✭ 277 (-0.72%)
Mutual labels:  functional-programming
asp-net-core-exception-handling
ASP.NET Core exception handling policies middleware
Stars: ✭ 34 (-87.81%)
Mutual labels:  exception-handling
Csound Expression
Haskell Framework for Electronic Music
Stars: ✭ 257 (-7.89%)
Mutual labels:  functional-programming
Zio Prelude
A lightweight, distinctly Scala take on functional abstractions, with tight ZIO integration
Stars: ✭ 267 (-4.3%)
Mutual labels:  functional-programming
Quark
Common combinators for Elixir
Stars: ✭ 279 (+0%)
Mutual labels:  functional-programming
Underscore.py
Python port of underscore.js
Stars: ✭ 277 (-0.72%)
Mutual labels:  functional-programming

Checked-Exceptions-enabled Java 8+ Functional Interfaces

and adapters

Build Status License Maven Central

Rationale

Standard java.util.function Functional Interfaces aren't checked-exception-friendly due to the absence of throws ... clause which results in tedious and verbose necessity of handling them by adding try-catch boilerplate.

Which makes one-liners like this:

path -> new URI(path)

become as verbose as:

path -> {
    try {
        return new URI(path);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

By applying com.pivovarit.function functional interfaces, it's possible to regain clarity and readability:

ThrowingFunction<String, URI, URISyntaxException> toUri = URI::new;

and use them seamlessly with native java.util.function classes by using custom ThrowingFunction#unchecked adapters:

...stream()
  .map(unchecked(URI::new)) // static import of ThrowingFunction#unchecked
  .forEach(System.out::println);

which avoids ending up with:

 ...stream().map(path -> {
     try {
         return new URI(path);
     } catch (URISyntaxException e) {
         throw new RuntimeException(e);
     }}).forEach(System.out::println);

Basic API

Functional Interfaces

Adapters

  • static Function<T, R> unchecked(ThrowingFunction<> f) {...}

Transforms a ThrowingFunction instance into a standard java.util.function.Function by wrapping checked exceptions in a RuntimeException and rethrowing them.

  • static Function<T, Optional<R>> lifted() {...}

Transforms a ThrowingFunction instance into a regular Function returning result wrapped in an Optional instance.

  • default ThrowingFunction<T, Void, E> asFunction() {...}

Returns Throwing(Predicate|Supplier|Consumer) instance as a new ThrowingFunction instance.

Maven Central

<dependency>
    <groupId>com.pivovarit</groupId>
    <artifactId>throwing-function</artifactId>
    <version>1.5.1</version>
</dependency>
Gradle
compile 'com.pivovarit:throwing-function:1.5.1'

Dependencies

None - the library is implemented using core Java libraries.

Version history

1.5.1 (06-05-2020)

  • Fixed visibility issues with ThrowingIntFunction

1.5.0 (26-01-2019)

  • Introduced proper Semantic Versioning
  • Introduced ThrowingIntFunction
  • Moved interfaces to com.pivovarit.function
  • Removed controversial unwrap() functionality
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].