Split list into two equal lists in F#

后端 未结 7 419
遇见更好的自我
遇见更好的自我 2021-01-12 18:21

I\'m really new to F#, and I need a bit of help with an F# problem.

I need to implement a cut function that splits a list in half so that the output would be...

相关标签:
7条回答
  • 2021-01-12 19:20

    You can use List.nth for random access and list comprehensions to generate a helper function:

    let Sublist x y data = [ for z in x..(y - 1) -> List.nth data z ]
    

    This will return items [x..y] from data. Using this you can easily generate gencut and cut functions (remember to check bounds on x and y) :)

    0 讨论(0)
提交回复
热议问题