Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6100697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:25:00+00:00 2026-05-23T13:25:00+00:00

How could I write this C# code in F# or Haskel, or a similar

  • 0

How could I write this C# code in F# or Haskel, or a similar functional language?

var lines = File.ReadAllLines(@"\\ad1\\Users\aanodide\Desktop\APIUserGuide.txt");

// XSDs are lines 375-471
var slice = lines.Skip(374).Take(471-375+1);

var kvp = new List<KeyValuePair<string, List<string>>>(); 
slice.Aggregate(kvp, (seed, line) => 
{
    if(line.StartsWith("https"))
        kvp.Last().Value.Add(line);
    else
        kvp.Add(
            new KeyValuePair<string,List<string>>(
                line, new List<string>()
            )
        );
    }
    return kvp;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:25:00+00:00Added an answer on May 23, 2026 at 1:25 pm

    So, if I read your code correctly, your input looks something like this:

    [...]
    Foo
    https://example1.com
    https://example2.com
    Bar
    https://example3.com
    Baz
    Xyzzy
    https://example4.com
    [...]
    

    From this, you want the headers grouped with the URLs below them. Here’s a Haskell program that does this:

    import Data.List (isPrefixOf)
    
    groupUrls :: [String] -> [(String, [String])]
    groupUrls [] = []
    groupUrls (header:others) = (header, urls) : groupUrls remaining
      where (urls, remaining) = span (isPrefixOf "https") others
    
    main = do
        input <- readFile "\\\\ad1\\\\Users\\aanodide\\Desktop\\APIUserGuide.txt"
        let slice = take (471 - 375 + 1) $ drop 374 $ lines input
        let kvp = groupUrls slice
        print kvp
    

    Output:

    [("Foo",["https://example1.com","https://example2.com"]),("Bar", ["https://example3.com"]),("Baz",[]),("Xyzzy",["https://example4.com"])]
    

    The key function of interest here is span, which is used here to take the consecutive lines starting with "https" and return them together with the remaining lines, which are then dealt with recursively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How could I write this in real code? if (!UIImageView with origin.x > 50.0)
could you tell me a way to write this code in a better way
I am using this code to write to a file in java. it has
Sure I could write this myself, but before I go reinventing the wheel is
I could probably write this myself, but the specific way I'm trying to accomplish
Probably really easy for a pro, but could someone re-write this from it's PHP
I could write myself a helper class that does this when given a functor,
I was hoping someone could give me a hand on how I write this
when releasing an instance that could exist or not, I usually write this: if
I wonder if I could write a program in the C -programming language that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.