JS disgusts me
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
A true FP programmer would make it apply
instead of run
...
Ahem, map...
And, of course, everything is a lazy list even if the functions can't handle more than one element in each list.
Dont look at C++ with std:: function
I'm pretty sure this post is designed to kill the soul. I am made slightly worse for witnessing this abortion of an implementation and I will never be quite the same again.
I think that's called a functor.
OP, what's your address? I have a "present" for you
It's just Java
Yep, some code examples from the official documentation. This:
printPersons(
roster,
(Person p) -> p.getGender() == Person.Sex.MALE
&& p.getAge() >= 18
&& p.getAge() <= 25
);
...is syntactic sugar for this:
interface CheckPerson {
boolean test(Person p);
}
printPersons(
roster,
new CheckPerson() {
public boolean test(Person p) {
return p.getGender() == Person.Sex.MALE
&& p.getAge() >= 18
&& p.getAge() <= 25;
}
}
);
...which is syntactic sugar for this:
interface CheckPerson {
boolean test(Person p);
}
class CheckPersonEligibleForSelectiveService implements CheckPerson {
public boolean test(Person p) {
return p.gender == Person.Sex.MALE &&
p.getAge() >= 18 &&
p.getAge() <= 25;
}
}
printPersons(roster, new CheckPersonEligibleForSelectiveService());
The printPersons
function looks like this:
public static void printPersons(List<Person> roster, CheckPerson tester) {
for (Person p : roster) {
if (tester.test(p)) {
p.printPerson();
}
}
}
Basically, if you accept a parameter that implements an interface with only one method (CheckPerson
), then your caller can provide you an object like that by using the lambda syntax from the first example.
They had to retrofit lambdas into the language, and they sure chose the one hammer that the language has.
Source: https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
Golang also does this, but it's not classes.
Amazing, lol