ฟังก์ชัน Cycle

wk
wk
Jul 10, 2017 · 1 min read

ฟังก์ชัน cycle สามารถ generate อินพุทให้เป็นข้อมูลชุดใหม่ ออกมาอย่างต่อเนื่อง เช่น ถ้าส่ง [1,2,3] เข้าไป cycle จะสร้างชุดข้อมูล [1,2,3,1,2,3,1,2,3 …] วนไปเรื่อย ๆ

แต่เนื่องจากคุณสมบัติ lazy evaluation ทำให้ข้อมูลจะไม่ถูกสร้างในทันที่ แต่จะสร้างก็ต่อเมื่อมีการเรียกใช้ เช่น เรียกผ่านฟังก์ชัน print, printfn และ Console.WriteLine ตามตัวอย่าง (ในตัวอย่างจะมีการใช้ร่วมกับฟังก์ชัน rotate)

Haskell

F#

C#

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade