Zip lists with F#
Problem Statement:
Zip two lists of Integers.
If the lists are of unequal length, return None; otherwise return Some of (int*int) list.
Solution:
Following naïve solution recurses over elements of the lists, and creates tuple, as part of the zip operation. If both lists are empty, it returns Some [].
[gist]4511771[/gist]
The unequal length case is handled by the pattern outlined in line 8 , which simply returns None. Subsequent return calls of the recursion detect it and simply return None.
Thus, resultant signature of zipTwo is given by:
[gist]4511784[/gist]
Output:
[gist]4511794[/gist]
Comments ()