Skip to content

Instantly share code, notes, and snippets.

@americodls americodls/method_reference.md Secret
Created May 19, 2017

Embed
What would you like to do?
How to languages implement method reference

Javascript

// Method Reference -> Math.sqrt
// Example

var roots = [1, 4, 9].map(Math.sqrt);

Java

import java.util.stream.DoubleStream;
// Method Reference -> Math::sqrt
// Example

double[] roots = DoubleStream.of(1, 4, 9).map(Math::sqrt).toArray();

Python

# Method Reference -> math.sqrt
# Example

import math
roots =  map(math.sqrt, [1, 4, 9])

Clojure

;; Method Reference -> #(Math/sqrt %)
;; Example

(map #(Math/sqrt %) [1, 4, 9])

Ruby

# Method Reference -> Math.method(:sqrt)
# Example
roots = [1, 4, 9].map &Math.method(:sqrt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.