Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Learn a little bit of Scala's Currying function every day

2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Curring function definition?

Convert a function that originally takes two arguments into two functions. The first function receives the first argument, and then returns the second function that receives the second argument.

In the process of function call, it becomes the form of continuous call of two functions.

It is also reflected in the marathon source code as well as the Spark source code, so understand the Curring function in the form of () ().

2. Examples:

Object CurryingTest {def main (args: Array [String]): Unit = {println ("- >:\ t" + sum (3jin4)) println ("- >:\ t" + sum2 (5)) println ("- >:\ t" + sum2 (5) (1)) / / Corey function println ("- >:\ t" + sum3 (4) (8))} def sum (a: Int) B: Int) = a + b def sum2 (a: Int) = (b: Int) = > a + b / / the intermediate process def sum3 (a: Int) (b: Int) = a + b} when converting a sum function into a sum3 function

In fact, there is no real understanding of what scenarios the Curry function is used in.

For now, it's just that as long as you see

Sum3 (a: Int) (b: Int) = a + b

This form can be directly understood as or equivalent to

Sum (a: Int, b: Int) = a + b

Form

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report