Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Functional Snippet] Multi-Consumers

Featured Replies

Inspired by: https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html

 

The functional package does provide a Consumer (1 arg) and a BiConsumer (2args) but you're on your own if you want more args. I stopped at 5 because I have never really needed more than that.

 

Example

    public static void main(String[] args) {
        Consumer.One<String> printInput = input -> System.out.println(input);
        Consumer.Two<Integer, Double> printSum = (a, b) -> System.out.println(a + b);
        //...
        Consumer.Five<Integer, Integer, Integer, Integer, Integer> printMultiplication = (a, b, c, d, e) ->System.out.println(a * b * c * d *e);
    }

Consumers

/**
 * Represents an operation that accepts one or multiple arguments and returns no result.
 *
 * Created by Botre on 24/05/2016.
 */
public final class Consumer {

    private Consumer() {

    }

    private interface IConsumer {
   
    }

    @FunctionalInterface
    public interface One<A> extends IConsumer {

        void consume(final A a);

    }

    @FunctionalInterface
    public interface Two<A, B> extends IConsumer {

        void consume(final A a, final B b);

    }

    @FunctionalInterface
    public interface Three<A, B, C> extends IConsumer {

        void consume(final A a, final B b, final C c);

    }

    @FunctionalInterface
    public interface Four<A, B, C, D> extends IConsumer {

        void consume(final A a, final B b, final C c, final D d);

    }

    @FunctionalInterface
    public interface Five<A, B, C, D, E> extends IConsumer {

        void consume(final A a, final B b, final C c, final D d, final E e);

    }

}
  • 5 weeks later...
  • Author

lol do u know what curried functions are

 

Java doesn't have variadic generics.

These are multi-type consumers.

Java doesn't have variadic generics.

These are multi-type consumers.

o true

why do u finalize params? final on locals is useless, maybe for clarity but in this case its just an interface method

Edited by Gangsta Homie

  • Author

o true

why do u finalize params? final on locals is useless, maybe for clarity but in this case its just an interface method

 

In my opinion, it's safer to finalize everything by default as opposed to leaving everything virtual by default.

 

I prefer to selectively unlock doors instead of selectively locking them, I'm an eternal pessimist who's afraid of getting robbed.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.