This document lists the functions available in the embedded FScript prelude (stdlib).
The stdlib is loaded automatically by FScript.Language before user scripts.
ListOptionMapIntFloatBoolString
Env : Environmentprint : string -> unitignore : 'a -> unit
type Environment = { ScriptName: string option; Arguments: string list }type FsKind = File of string | Directory of string | Missinglet Env : Environment- Injected by the CLI and REPL hosts.
Env.ScriptNameisSome "<path>"for file execution andNonefor stdin/REPL execution.Env.Argumentscontains script arguments passed after--.
- Functions are curried.
- The stdlib is part of the language runtime and is always available.
- Top-level script bindings cannot collide with reserved stdlib names.
printandignoreare built-in language functions, not host externs.
- Indexer:
values[index] : 'a option - Signature:
'a list -> int -> 'a option - Description:
- zero-based optional index access
- negative or out-of-range indices return
None
- Indexer:
values[key] : 'v option - Signature:
'v map -> string -> 'v option - Description:
- optional lookup by string key
- missing keys return
None - map keys are string-only
- Constructors:
Some : 'a -> 'a optionNone : 'a option
- Field access:
record.Field - Signature:
{ Field: 'a; ... } -> 'a
- Access model:
- tuples are consumed via destructuring and pattern matching
- tuples do not have a native indexer
List.empty : 'a listList.map : ('a -> 'b) -> 'a list -> 'b listList.iter : ('a -> unit) -> 'a list -> unitList.choose : ('a -> 'b option) -> 'a list -> 'b listList.collect : ('a -> 'b list) -> 'a list -> 'b listList.exists : ('a -> bool) -> 'a list -> boolList.contains : 'a -> 'a list -> boolList.rev : 'a list -> 'a listList.distinct : 'a list -> 'a listList.fold : ('state -> 'a -> 'state) -> 'state -> 'a list -> 'stateList.filter : ('a -> bool) -> 'a list -> 'a listList.length : 'a list -> intList.tryFind : ('a -> bool) -> 'a list -> 'a optionList.tryGet : ('a -> bool) -> 'a list -> int optionList.tryItem : int -> 'a list -> 'a optionList.tryHead : 'a list -> 'a optionList.tail : 'a list -> 'a listList.append : 'a list -> 'a list -> 'a list
Option.defaultValue : 'a -> 'a option -> 'aOption.defaultWith : (unit -> 'a) -> 'a option -> 'aOption.isNone : 'a option -> boolOption.isSome : 'a option -> boolOption.map : ('a -> 'b) -> 'a option -> 'b option
Map.empty : 'v map
Alias of{}.Map.tryGet : string -> 'v map -> 'v optionMap.containsKey : string -> 'v map -> boolMap.add : string -> 'v -> 'v map -> 'v mapMap.ofList : (string * 'v) list -> 'v mapMap.fold : ('state -> string -> 'v -> 'state) -> 'state -> 'v map -> 'stateMap.count : 'v map -> intMap.filter : (string -> 'v -> bool) -> 'v map -> 'v mapMap.choose : (string -> 'v -> 'u option) -> 'v map -> 'u mapMap.map : ('v -> 'u) -> 'v map -> 'u mapMap.iter : (string -> 'v -> unit) -> 'v map -> unitMap.remove : string -> 'v map -> 'v map
Map keys in FScript are string-only.
Int.tryParse : string -> int optionInt.toString : int -> string
Float.tryParse : string -> float optionFloat.toString : float -> string
Bool.tryParse : string -> bool optionBool.toString : bool -> string
String.replace : string -> string -> string -> string- argument order:
oldValue -> newValue -> source
- argument order:
String.indexOf : string -> string -> int option- argument order:
value -> source
- argument order:
String.toLower : string -> stringString.toUpper : string -> stringString.substring : int -> int -> string -> string option- argument order:
start -> length -> source
- argument order:
String.concat : string -> string list -> stringString.split : string -> string -> string list- argument order:
separator -> source
- argument order:
String.endsWith : string -> string -> bool- argument order:
suffix -> source
- argument order:
let xs = List.map (fun x -> x + 1) [1;2;3]
let found = List.tryFind (fun x -> x > 2) xs
let maybeSecond = List.tryItem 1 xs
let maybePort = Some 8080
let port = maybePort |> Option.defaultValue 80
let m = { ["a"] = 1; ["b"] = 2 }
let hasA = Map.containsKey "a" m
let one = m["a"] |> Option.defaultValue 0
let first = xs[0] |> Option.defaultValue 0
match Env.Arguments with
| scriptPath :: _ -> print scriptPath
| [] -> print "no args"