Get the App
SLTechnology News&Howtos  ›  Development  › 

How to screw the code together in Scala

Shulou Source: shulou.com Published: 2022-06-02 07:18:38 09月12日 Update

This article introduces the relevant knowledge of "how to screw the code together in Scala". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The fun way to practice all these elements of the layout library is to write a program that draws spirals on a given number of boundaries.

Import Element.elem object Spiral {val space = elem (") val corner = elem (" + ") def spiral (nEdges: Int, direction: Int): Element = {if (nEdges = = 1) elem (" + ") else {val sp = spiral (nEdges-1, (direction + 3)% 4) def verticalBar = elem ('|', 1, sp.height) def horizontalBar = elem ('-', sp.width 1) if (direction = = 0) (corner beside horizontalBar) above (sp beside space) else if (direction = = 1) (sp above space) beside (corner above verticalBar) else if (direction = = 2) (space beside sp) above (horizontalBar beside corner) else (verticalBar above corner) beside (space above sp)} def main (args: Array [String]) {val nSides = args (0). ToInt println (spiral (nSides, 0))}}

Because Spiral is a separate object with the appropriate signature of the main method, it is a Scala program. Spiral takes a command-line argument, an integer, and draws a spiral with a specific number of boundaries. For example, you can draw a six-boundary spiral as shown on the left below, or a larger spiral like the one on the right (slightly)

This is the end of the content of "how to screw the code together in Scala". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Spirals boundaries code content quantity methods more knowledge programs appropriateness fun fun utility learning next elements parameters right commands dilemmas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL OPPO Reno vpn Linux