-
Notifications
You must be signed in to change notification settings - Fork 4
Supplier Functional Interface & Lazy
We've seen this being used so many times, but I did not have much of an idea of what it really meant, and why we were using it. After doing some research, I present to everyone what I have found out!
The Supplier interface represents an operation that takes no argument and returns a result. For example,
Supplier<T> s = () -> foo();
. You would pass s
to a new Constructor(Supplier<T> supplier);
, which then updates the supplier
attribute of that newly instantiated class. Remember, Supplier is a functional interface meaning you'd have to pass it as a function.
The idea of Lazy evaluation comprises of two things: 1. Delayed Evaluation, 2. Memoization(Caching) That's pretty much all you need to know about the brief overview of Lazy! In other words, lazy eval is all about optimization --> you don't evaluate what you don't need, and once evaluated it is memoized.
Imagine you're a Software Engineer at ABC company, and you have a huge list of say 10 million elements. Assuming that you manipulate your list multiple times or are evaluating certain sequences, it would be extremely inefficient to not have this list in a Lazy format. This would drastically worsen the run time of your code, which can be improved in certain situations by making the list Lazy.
I strongly suggest catching up on Prof Henry's lecture 9. I was very confused before watching the lecture, but just 30 mins into it I was able to clear most of my misunderstandings on Lazy and the Supplier functional Interface.
Peer Learning
Guides
Setting Up Checkstyle
Setting Up Java
Setting Up MacVim
Setting Up Stu
Setting Up Unix For Mac
Setting Up Unix For Windows
Setting Up Vim
Setting up SSH Config
SSH Without Password
Copying Files From PE Nodes
Using tmux
CS2030 Contents
Lecture 1 SummaryLecture 2 Summary
Access Modifiers
Lecture 3 Summary (Polymorphism)
Compile Time Type VS Runtime Type
Abstraction, Encapsulation, Inheritance, and Polymorphism
SOLID Principles
Class VS Abstract Class VS Interface
Comparable VS Comparator
Generic Types T
HashMap
Raw Types with Generic
Lambda expression
PECS (Producer Extends Consumer Super)
Optional
Streams
Parallel Streams
Monad
Functors and Monads with Category Theory