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 844393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:16:44+00:00 2026-05-15T06:16:44+00:00

let reader = selectCommand.ExecuteReader() let getBytesData (x : IDataReader) = let len = reader.GetBytes(1,

  • 0
let reader = selectCommand.ExecuteReader()

let getBytesData (x : IDataReader) = 
    let len = reader.GetBytes(1, int64 0, null, 0, 0);
    // Create a buffer to hold the bytes, and then
    // read the bytes from the DataTableReader.
    let buffer : byte array = Array.zeroCreate (int32 len)
    x.GetBytes(1, int64 0, buffer, 0, int32 len) |> ignore
    buffer

let retVal = 
  List [ while reader.Read() do 
           yield (reader.GetString(0), getBytesData reader, 
                  reader.GetDateTime(2)) ]

I have above code to read bytes[] from datareader.

getBytesData function takes reader and returns bytes[] from reader.

  • everything works fine but it getBytesData function is working very non-functional way.
  • i am creates zero filled byte array just to create array, is there any way of creating dynamic expanding or fixed lenght array

Is there any way i can optimize in F#?

Sorry for kind of question, but i have started a new project on F# to squeeze all juice out of it, so trying to get each line most optimal way

  • 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-15T06:16:45+00:00Added an answer on May 15, 2026 at 6:16 am

    The GetBytes method of the IDataReader doesn’t really provide any options for writing the code in a more functional way (it takes an array that it wants to modify, so we simply must give it some array…).

    So your version of code is perfectly fine – even though it’s not fully functional, you can at least keep the imperative part localized in that single function and keep the rest of your program functional (which is a good result)!

    The only change I would do in your code is that I would move reader to the sequence comprehension (to make it more localized) and I would use the use keyword to make sure that it gets properly disposed (also, you don’t need the List identifier in the sequence expression):

    let retVal =  
      [ use reader = selectCommand.ExecuteReader() 
        while reader.Read() do  
          yield (reader.GetString(0), getBytesData reader,  reader.GetDateTime(2)) ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let retVal = if reader.Read() then (reader.GetString(0), getBytesData reader 1, reader.GetDateTime(2)) else null F#
Let say I want to create comic reader app where the user can download
Is there a better (shorter?) way than the following? let cpucount = System.UInt16.Parse( reader.GetInt32(3).ToString()
OK so I have 4 buffers, 3 FBOs and a render buffer. Let me
Let's say that I have a SQLite database that I create in a separate
First, let's see the code: //The encoding of utf8.txt is UTF-8 StreamReader reader =
Let's say we want to use ReaderT [(a,b)] over the Maybe monad, and then
Let's say I'm programming in a threading framework that does not have multiple-reader/single-writer mutexes
So let's say I have the following setup in Google Reader Folder One Engadget
Let's say I'm writing a eBook reader for Windows Phone 7. Now the first

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.