How do I split up a collection by number of elements?
For example, if I have the following:
0,1,2,3,4,5,6,7,8
How could I partition the collection into 3 sets:
0,1,2
3,4,5
6,7,8
NOTE: F# is extremely foreign to me. So forgive my ignorance.
Here's a TicTacToe exercise that I am trying to learn F# with. In the code, I am using Seq.take and Seq.skip.
How could I write this differently?
module TicTacToe
open FsUnit
open NUnit.Framework
[<Test>]
let ``player has connected row`` () =
let grid = Map.empty
.Add(0, true).Add(1, true).Add(2, true)
.Add(3, true).Add(4, false).Add(5, true)
.Add(6, true).Add(7, true).Add(8, true)
let firstRowIsStreak = grid
|> Seq.take 3
|> Seq.forall (fun x -> x.Value = true)
let secondRowIsStreak = grid
|> Seq.skip 3
|> Seq.take 3
|> Seq.forall (fun x -> x.Value = true)
let thirdRowIsStreak = grid
|> Seq.skip 6
|> Seq.take 3
|> Seq.forall (fun x -> x.Value = true)
firstRowIsStreak |> should equal true
secondRowIsStreak |> should equal false
thirdRowIsStreak |> should equal true