瀏覽代碼

Implement applyi

DricomDragon 5 年之前
父節點
當前提交
51226f5096
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      tp/mine-sweeper/main.hs

+ 5 - 0
tp/mine-sweeper/main.hs

@@ -94,6 +94,11 @@ updateGrid g m =
     let Grid cm = g in
     Grid (zipWith (zipWith updateCell) cm m)
 
+applyi::(a -> a) -> Int -> [a] -> [a]
+applyi f i xs =
+    let (xs1, xs2) = splitAt i xs in
+    concat [xs1, ( (f (head xs2)) : tail xs2 )]
+
 
 -- Testing data