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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:20:13+00:00 2026-06-18T13:20:13+00:00

Given a string of digits, I would like to have a sequence of tuples

  • 0

Given a string of digits, I would like to have a sequence of tuples mapping the non-zero characters with their position in the string. Example:

IN: "000140201"
OUT: { (3, '1'); (4, '4'); (6, '2'); (8, '1') }

Solution:

let tuples = source
             |> Seq.mapi (fun i -> fun c -> (i, c))
             |> Seq.filter (snd >> (<>) '0')

It seems like (fun i -> fun c -> (i, c)) is a lot more typing than it should be for such a simple and presumably common operation. It’s easy to declare the necessary function:

let makeTuple a b = (a, b)
let tuples2 = source
              |> Seq.mapi makeTuple
              |> Seq.filter (snd >> (<>) '0')

But it seems to me that if the library provides the snd function, it should also provide the makeTuple function (and probably with a shorter name), or at least it should be relatively easy to compose. I couldn’t find it; am I missing something? I tried to build something with the framework’s Tuple.Create, but I couldn’t figure out how to get anything other than the single-argument overload.

  • 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-06-18T13:20:15+00:00Added an answer on June 18, 2026 at 1:20 pm

    But it seems to me that if the library provides the snd function, it should also provide the makeTuple function.

    F# assumes that you decompose tuples (using fst, snd) much more often than composing them. Functional library design often follows minimal principle. Just provide functions for common use cases, other functions should be easy to define.

    I couldn’t find it; am I missing something?

    No, you aren’t. It’s the same reason that FSharpPlus has defined tuple2, tuple3, etc. Here are utility functions straight from Operators:

    /// Creates a pair
    let inline tuple2 a b = a,b
    /// Creates a 3-tuple
    let inline tuple3 a b c = a,b,c
    /// Creates a 4-tuple
    let inline tuple4 a b c d = a,b,c,d
    /// Creates a 5-tuple
    let inline tuple5 a b c d e = a,b,c,d,e
    /// Creates a 6-tuple
    let inline tuple6 a b c d e f = a,b,c,d,e,f
    

    I tried to build something with the framework’s Tuple.Create, but I couldn’t figure out how to get anything other than the single-argument overload.

    F# compiler hides properties of System.Tuple<'T1, 'T2> to enforce pattern matching idiom on tuples. See Extension methods for F# tuples for more details.

    That said, point-free style is not always recommended in F#. If you like point-free, you have to do a bit of heavy lifting yourself.

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

Sidebar

Related Questions

Example: there must be at least two digits in a given string independent of
I have a String and I want to extract the (only) sequence of digits
I'm in need to modify a given string to contain only alpha numerical characters,
How do I create an array in smarty from a given string like 22||33||50
I have used the crypt function in c to encrypt the given string. I
what would be the regular expression to check if a given string contains atleast
I was wondering how I would convert a string of four to six digits
I would like to replace leading spaces in a string of formatted numbers by
In PHP, given the final string length the range of characters it can use
I would like to introduce look-and-say sequence at first. It goes like a =

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.