Note that there are some explanatory texts on larger screens.

plurals
  1. POProject new values from existing value
    text
    copied!<p>I'm writing my very first F# program, the aim being simply to learn F#.</p> <p>What I want to is provide a list of dates, and attributes (e.g.DayOfWeek, DayOfMonth) of those dates. I have managed to provide the list of dates and I know that the .net Framework gives me everything I need to extract all the attributes, I just can't figure out how to add the attribute as new columns in my list. Here's what I have so far:</p> <pre><code>type Span = Span of TimeSpan with static member (+) (d:DateTime, Span wrapper) = d + wrapper //this is defining the + operator static member Zero = Span(new TimeSpan(0L)) type Dates() = let a = DateTime.Parse("01/12/2013") let b =DateTime.Parse("02/12/2013") let ts = TimeSpan.FromDays(1.0) member this.Get() = [a .. Span(ts) .. b] let mydates = new Dates() mydates.Get() </code></pre> <p>When I run that code I get a list of DateTime values, with 2 records in the list. I can now do something like this:</p> <pre><code>mydates.Get() |&gt; List.map (fun x -&gt; x.DayOfWeek);; </code></pre> <p>which returns:</p> <blockquote> <p>val it : DayOfWeek list = [Sunday; Monday]</p> </blockquote> <p>or </p> <pre><code>mydates.Get() |&gt; List.map (fun x -&gt; x.DayOfYear);; </code></pre> <p>which returns:</p> <blockquote> <p>val it : int list = [335; 336]</p> </blockquote> <p>That's all great, however what I would like to do is project a list that has 2 "columns" (if columns is the right word) so that my output is (something like):</p> <blockquote> <p>val it : int list = [(Sunday,335); (Monday,336)]</p> </blockquote> <p>I hope that explains what I'm after.</p> <p>thanks</p> <p>Jamie</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload