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

  • Home
  • SEARCH
  • 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 9177495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:20:21+00:00 2026-06-17T17:20:21+00:00

I wish I could do: let myFun param1 param2 = ….. if condition 1

  • 0

I wish I could do:

 let myFun param1 param2 = 
      .....
      if condition 1
          ....
          if condition 2
               yield ....

 let sequence = seq { for x in xs do
                            myFun 1 x
                            myFun 2 x
                    }

But now I can only do

 let myFun param = 
      .....
      .....
      if condition 1
          ....
          if condition 2
               Some....
          else None    // has to complete else
      else None

 let sequence = seq { for x in xs do
                        match myFun 1 x with
                        | Some x -> yield x
                        | None   -> ()
                        match myFun 2 x with
                        | Some x -> yield x
                        | None   -> ()
                    }

  let sequence2 =  // order will be different, and we can not have index passed into function unless we do a futher Seq.map

       let a = xs |> Seq.choose (myFun 1)
       let b = xs |> Seq.choose (myFun 2)
       Seq.append a b

My real code:

The code looks not that good a few None and I tried Seq.choose, which is not that helpful since it doesn’t support Seq.choosei.

        let exam isForward brickID =
            let brick = state.[brickID]
            let (nextTR, nextOccupied, nextUnoccupied) = if isForward then brick.Body.nudgeForward () else brick.Body.nudgeBack ()
            if (nextOccupied.isInGrid gridSize) && (map.ContainsKey nextOccupied |> not) then
                let nextBrick = { brick with Body = nextTR }
                let nextState = getNextState state brickID nextBrick
                if not (explored.Contains nextState) then
                    let nextMap = map |> Map.remove nextUnoccupied
                                      |> Map.add nextOccupied nextBrick
                    Some ((nextState, nextMap), (nextBrick, if isForward then brick.Body.Direction else brick.Body.Direction.Opposite))
                else None
            else None

        seq { for brickID in 0 .. state.Length - 1 do
                match exam true brickID with
                | Some x -> yield x
                | None   -> ()
                match exam false brickID with
                | Some x -> yield x
                | None   -> ()
        }
  • 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-17T17:20:22+00:00Added an answer on June 17, 2026 at 5:20 pm

    Your exam function could return a sequence that is either empty (instead of None) or contains exactly one element (instead of Some) and use yield! which adds all elements of a given sequence to the one that you’re generating at the moment.

    In your pseudo-code sample, this would look as:

    let myFun param1 param2 param3 = seq {
      if param1 then
        if param2 then
          yield param3 }
    
     let sequence = seq { 
       for x in xs do
         yield! myFun true true x 
         yield! myFun true true (x * 10) }
    

    Assuming xs = [1;2] the above sample generates [1; 10; 2; 20] (and if you set some of the true arguments to false, it will skip some of the numbers)

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

Sidebar

Related Questions

Well, sad to say, but I have 2 questions, which I wish I could've
I wish I could paste in my markup, but it's too complex and contains
I wish HTML could do something semantically equivalent to this; <dl class=main-list> <definitionitem> <dt>Some
I wish I could figure this out. I need to produce a table with
I wish I could throw a ! on a Google search, and turn up
Is there any good practice for this? I wish I could solve the problem
I wish to make the uploaded file contents only viewable on the browser i.e
I wish to do this using only XAML - How to add an additional
I wish to create a subtree from an hclust object. For example, let's say
type A = { ... id: int; ... } I wish i could do

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.