[JAVA] Try using F # list

At the beginning

I played around with the F # list

Sample source

module File1
//Try using a list
//Declare a list
let strs= ["dogs";"cats";"bird"]

//Try declaring the format with printfn
printfn "%A" strs //["dogs"; "cats"; "bird"]Is displayed
printfn "%O" strs //[dogs; cats; bird]Is displayed

//Access the list using pattern matching
//Pattern match 1
let rec accessList strs =
    match strs with
    |x::xs->printfn "%O " x;printfn "%O " (accessList xs);x+" a"
    |[]->printfn "The end";"b"

//Pattern match 2
let rec accessList2 strs =
    match strs with
    |x::xs->printf "%O " x; accessList2 xs
    |[]->printfn "The end";

in
//There is a return value, so you need to bind the result with let
let a=accessList strs
//dogs
//cats
//bird
//The end
//b
//bird a
//cats a
//Is displayed

printfn  "Display the result bound by let"
printfn "%s" a
//Display the result bound by let
//dogs a
//Is displayed

accessList2 strs
//dogs cats bird The end is displayed

Note

About the execution image of Part 1 "Pattern Match Part 1"

It looks like the output result of the program is seen, and it looks like the figure below. image If you start from the matching part with []->, it may be easier to grasp the execution image of recursive processing.

About the list of functional languages

It's an image that has both Java List and Deque (Stack) properties. Lists in functional languages seemed to have smoother list operations than Java Lists, but if they also have the properties of Deque (Stack), that might be natural.

Recommended Posts

Try using F # list
Try using libGDX
Try using Maven
Try using sql-migrate
Try using SwiftLint
Try using Log4j 2.0
Try using Axon Framework
Try using JobScheduler's REST-API
Try using java.lang.Math methods
Try using PowerMock's WhiteBox
Try using Talend Part 2
Try using Talend Part 1
Try using each_with_index method
Try using Spring JDBC
Try using GloVe with Deeplearning4j
Try using view_component with rails
Try scraping using java [Notes]
Try using Cocoa from Ruby
[Swift] Try using Collection View
Try using IntelliJ IDEA once
Try using Spring Boot Security
Try using gRPC in Ruby
[Rails] Try using Faraday middleware
[Processing] Try using GT Force.
[Programming Encyclopedia] ยง2 Try using Ruby
People using docker Try using docker-compose
Enumeration of combination patterns using List
Try using Redmine on Mac docker
Try using Redis with Java (jar)
[Java] Try to implement using generics
Try using the messaging system Pulsar
Try using IBM Java method tracing
Try using Hyperledger Iroha's Java SDK
[Java] Where did you try using java?
How to sort a List using Comparator
Try using Java framework Nablarch [Web application]
Try using || instead of the ternary operator
Try using the service on Android Oreo
Try using the Stream API in Java
Try using the Rails API (zip code)
Study Java Try using Scanner or Map
Try using JSON format API in Java
Try using Spring Boot with VS Code
Try using Reladomo's MT Loader (Multi-Threaded Matcher Loader)
Try using Kong + Konga with Docker Compose.
Try using the Emotion API from Android
Try using the Wii remote with Java
Try using simple_form / edit even child models
Try implementing GraphQL server using grahpql-java-tools (+ kotlin)