2 people like it.
Like the snippet!
drop
Removes the nth element from a list
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
|
// -- | Auxiliary recursive drop function
let rec drop' i l1 p l2 =
if List.length l2 = List.length l1 - 1 then l2
else
let p = if p = i then p+1 else p
drop' i l1 (p+1) (List.append l2 [(List.nth l1 p)])
// -- | Removes the the nth element from list
let drop i l =
drop' i l 0 []
// -- | Use cases
let list = [1..10]
printfn "%A" drop 0 list
printfn "%A" drop 1 list
printfn "%A" drop (List.length list - 1) list
//Or: let drop n xs = Seq.concat([|Seq.take (n-1) xs; Seq.skip n xs|]);;
|
val drop' : i:int -> l1:'a list -> p:int -> l2:'a list -> 'a list
Full name: Script.drop'
val i : int
val l1 : 'a list
val p : int
val l2 : 'a list
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val length : list:'T list -> int
Full name: Microsoft.FSharp.Collections.List.length
val append : list1:'T list -> list2:'T list -> 'T list
Full name: Microsoft.FSharp.Collections.List.append
val nth : list:'T list -> index:int -> 'T
Full name: Microsoft.FSharp.Collections.List.nth
val drop : i:int -> l:'a list -> 'a list
Full name: Script.drop
val l : 'a list
Multiple items
val list : int list
Full name: Script.list
--------------------
type 'T list = List<'T>
Full name: Microsoft.FSharp.Collections.list<_>
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
More information