Reputation: 4606
I'm trying to create a pipeline that consists of the main parameter being a list with a constant.
As a simple example
type ClockType = | In | Out
let ClockMap index offset =
match index with
| index when index + offset % 2 = 0 -> In
| _ -> Out
let MapIt offset = [0 .. 23] |> List.map offset
It works when I take out the offset
. I've tried doing a tuple
but then it doesn't like the int list
. What is the best way to go about this?
I'm just learning F# so bear with me.
Upvotes: 0
Views: 104
Reputation: 62995
Is this what you're after?
type ClockType = In | Out
let clockMap offset index = if (index + offset) % 2 = 0 then In else Out
let mapIt offset = [0 .. 23] |> List.map (clockMap offset)
Output would be:
mapIt 3 |> printfn "%A"
// [Out; In; Out; In; Out; In; Out; In; Out; In; Out; In; Out; In; Out; In; Out;
// In; Out; In; Out; In; Out; In]
If so, there were multiple issues:
clockMap
's parameters were backwards%
has higher precedence than +
clockMap
was never being called (and offset
needs to be partially applied to clockMap
)The change from match
to if
was purely for readability, and idiomatically, non-literal let
bound values start with lowercase characters (type names and class properties/methods start with uppercase).
Upvotes: 3