Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fable-compiler/Fable
Browse files Browse the repository at this point in the history
  • Loading branch information
krauthaufen committed Apr 23, 2019
2 parents 951eaa2 + 37d2439 commit 442a503
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/fable-library/List.fs
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,22 @@ let splitAt i xs =
| 1, x::xs -> [x],xs
| i, xs -> takeSplitAux true i [] xs

let outOfRange() = failwith "Index out of range"

let slice (lower: int option) (upper: int option) (xs: 'T list) =
let lower = defaultArg lower -1
let lower = defaultArg lower 0
let upper = defaultArg upper -1
([], xs) ||> foldIndexed (fun i acc x ->
if (lower = -1 || lower <= i) && (upper = -1 || i <= upper)
then x::acc
else acc) |> reverse
if lower < 0 then outOfRange()
elif upper < lower then []
else
let mutable lastIndex = -1
let res =
([], xs) ||> foldIndexed (fun i acc x ->
lastIndex <- i
if lower <= i && i <= upper then x::acc
else acc)
if lower > (lastIndex + 1) || upper > lastIndex then outOfRange()
reverse res

let distinctBy (projection: 'T -> 'Key) (xs:'T list) ([<Inject>] eq: IEqualityComparer<'Key>) =
let hashSet = HashSet<'Key>(eq)
Expand Down

0 comments on commit 442a503

Please sign in to comment.