I have a recursive problem trying to use a library to generate forms dynamically. The library is Fable.Forms
If we were basing my problem with that page's first example, my goal would be to have email and password (and more fields obviously) in a collection, then have a recursive process that builds the form dynamically.
Here's a naive version of "solving" the problem:
let fields = [ fieldA; fieldB ]
match fields |> List.length with
| 1 ->
Form.succeed (fun _ -> Nothing)
|> Form.append (fields |> List.head)
| 2 ->
Form.succeed (fun _ _ -> Nothing)
|> Form.append (fields |> List.head)
|> Form.append (fields |> List.tail |> List.head)
| _ -> failwith "..... gotta solve using tail recursion!!"
My problem is that I need to know the exact number of fields in advance to give to the Form.succeed anonymous function the correct number of "input" arguments.
eg, if the list has:
- 1 fields, I need to call Form.succeed with (fun ? -> ...) then append fields in list
- 2 fields, I need to call Form.succeed with (fun ? ? -> ...) then append fields in list
- 3 fields, I need to call Form.succeed with (fun ? ? ? -> ...) then append fields in list.