मेरे पास दो कॉलम, टेक्स्ट और गिनती के साथ एक CSV फ़ाइल है। लक्ष्य इस से फ़ाइल को बदलने के लिए है:एफ # में, मैं एक बड़ी पाइपलाइन के संदर्भ में Seq.unfold का उपयोग कैसे करूं?
some text once,1
some text twice,2
some text thrice,3
इस के लिए
:
some text once,1
some text twice,1
some text twice,1
some text thrice,1
some text thrice,1
some text thrice,1
प्रत्येक पंक्ति गिनती बार दोहरा और है कि कई लाइनों पर गिनती फैल गया।
यह Seq.unfold लिए एक अच्छे उम्मीदवार की तरह मुझे लगता है,, अतिरिक्त लाइनें पैदा करने के रूप में हम फ़ाइल को पढ़ने। मैं निम्नलिखित जनरेटर समारोह है:
let expandRows (text:string, number:int32) =
if number = 0
then None
else
let element = text // "element" will be in the generated sequence
let nextState = (element, number-1) // threaded state replacing looping
Some (element, nextState)
FSI पैदावार एक निम्नलिखित समारोह हस्ताक्षर:
val expandRows : text:string * number:int32 -> (string * (string * int32)) option
FSI में निम्नलिखित को निष्पादित:
let expandedRows = Seq.unfold expandRows ("some text thrice", 3)
पैदावार की उम्मीद:
val it : seq<string> = seq ["some text thrice"; "some text thrice"; "some text thrice"]
सवाल यह है: मैं इसे एक बड़ी ईटीएल पाइपलाइन के संदर्भ में कैसे प्लग करूं? उदाहरण के लिए:
File.ReadLines(inFile)
|> Seq.map createTupleWithCount
|> Seq.unfold expandRows // type mismatch here
|> Seq.iter outFile.WriteLine
पाइपलाइन के संदर्भ में नीचे दी गई त्रुटि विस्तार पर है।
Type mismatch.
Expecting a 'seq<string * int32> -> ('a * seq<string * int32>) option'
but given a 'string * int32 -> (string * (string * int32)) option'
The type 'seq<string * int 32>' does not match the type 'string * int32'
मुझे उम्मीद थी कि विस्तार अलग-अलग परीक्षण में, स्ट्रिंग की सीईसी वापस कर रहा था। जैसा कि न तो "उम्मीद" या "दिया गया" है, मैं उलझन में हूं। क्या कोई मुझे सही दिशा दिखा सकता है?
कोड के लिए एक सार यहाँ है: https://gist.github.com/akucheck/e0ff316e516063e6db224ab116501498
बहुत उपयोगी स्पष्टीकरण; बिल्कुल मुझे क्या चाहिए। धन्यवाद! – akucheck
खुशी है कि मैं मदद कर सकता हूं। –