Skip to content

Instantly share code, notes, and snippets.

@nenono
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenono/3b13d869286ec0371252 to your computer and use it in GitHub Desktop.
Save nenono/3b13d869286ec0371252 to your computer and use it in GitHub Desktop.
任意型リストのjoin
let join (elm:'a) (lis:'a list) =
lis
|> List.fold (fun a x -> elm::x::a) [] // a=処理済みリスト x=現在の要素
|> (function
| x::xs -> xs
| xs -> xs) // 要素数2以上なら1つスキップ もう少し簡潔に書けないものか
|> List.rev
let test1 = join 0 [1;2;3;4;5;6] = [1;0;2;0;3;0;4;0;5;0;6] // -> true
let test2 = join 0 [] = [] // -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment