Module luafp.predicates
luafp predicates module.
Functions
isNil (o) | Predicate function that returns if the object you pass in is nil or not. |
isBoolean (o) | Predicate function that returns if the object you pass in is a Boolean or not. |
isNumber (o) | Predicate function that returns if the object you pass in is a Number or not. |
isString (o) | Predicate function that returns if the object you pass in is a String or not. |
isUserdata (o, typeFunction) | Predicate function that returns if the object you pass in is a Userdata or not. |
isFunction (o) | Predicate function that returns if the object you pass in is a Function or not. |
isThread (o) | Predicate function that returns if the object you pass in is a Thread or not. |
isTable (o) | Predicate function that returns if the object you pass in is a Table or not. |
exists (o) | Predicate function that returns if the object you pass in is not nil. |
isEmptyString (o) | Predicate function that returns if the object you pass in is an empty string, like '' |
isCow (o) | Predicate function that returns true if the object you pass is a cow |
Functions
- isNil (o)
-
Predicate function that returns if the object you pass in is nil or not.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's nil, false if it's not
Usage:
local isNil = require 'luafp.predicates'.isNil print(isNil(nil)) -- true print(isNil('cow')) -- false
- isBoolean (o)
-
Predicate function that returns if the object you pass in is a Boolean or not.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's a Boolean, false if it's not
Usage:
local isBoolean = require 'luafp.predicates'.isBoolean print(isBoolean(nil)) -- false print(isBoolean()) -- false print(isBoolean('cow')) -- false print(isBoolean('')) -- false print(isBoolean(true)) -- true print(isBoolean(false)) -- true
- isNumber (o)
-
Predicate function that returns if the object you pass in is a Number or not.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's a Number, false if it's not
Usage:
local isNumber = require 'luafp.predicates'.isNumber print(isNumber(1)) -- true print(isNumber(1.23)) -- true print(isNumber(1.0)) -- true print(isNumber('1')) -- false
- isString (o)
-
Predicate function that returns if the object you pass in is a String or not.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's a String, false if it's not
Usage:
local isString = require 'luafp.predicates'.isString print(isString('sup')) -- true print(isString('')) -- true print(isString(1)) -- false
- isUserdata (o, typeFunction)
-
Predicate function that returns if the object you pass in is a Userdata or not.
Parameters:
- o some object to check
- typeFunction type checker function, typically you'd use Lua's built in "type"
Returns:
-
yesOrNo true if it's an Userdata, false if it's not
Usage:
local isUserdata = require 'luafp.predicates'.isUserdata print(isUserdata(RobloxCharacter)) -- true print(isUserdata({})) -- false print(isUserdata(1)) -- false
- isFunction (o)
-
Predicate function that returns if the object you pass in is a Function or not.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's an Function, false if it's not
Usage:
local isFunction = require 'luafp.predicates'.isFunction print(isFunction(function() return true end)) -- true local cow = function() return true end print(isFunction(cow)) -- true local thing = {} thing.sup = function() return true end print(isFunction(thing.sup)) -- true print(isFunction({})) -- false
- isThread (o)
-
Predicate function that returns if the object you pass in is a Thread or not.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's an Thread, false if it's not
Usage:
local isThread = require 'luafp.predicates'.isThread function blade() print("blood") coroutine.yeild() print("is") coroutine.yeild() print("pumpin'") end co = coroutine.create(blade) print(isThread(blade)) -- false print(isThread(co)) -- true
- isTable (o)
-
Predicate function that returns if the object you pass in is a Table or not.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's an Table, false if it's not
Usage:
local isTable = require 'luafp.predicates'.isTable print(isTable(function() return true end)) -- false print(isTable({})) -- true
- exists (o)
-
Predicate function that returns if the object you pass in is not nil.
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's not nil, false if it's nil
Usage:
local exists = require 'luafp.predicates'.exists print(exists(function() return true end)) -- true print(exists({})) -- true print(exists()) -- false print(exists(nil)) -- false
- isEmptyString (o)
-
Predicate function that returns if the object you pass in is an empty string, like ''
Parameters:
- o some object to check, probably a string
Returns:
-
yesOrNo true if it's '', false if it's not
Usage:
local exists = require 'luafp.predicates'.isEmptyString print(isEmptyString('')) -- true print(isEmptyString("")) -- true print(isEmptyString('cow')) -- false print(isEmptyString(nil)) -- false print(isEmptyString(5)) -- false
- isCow (o)
-
Predicate function that returns true if the object you pass is a cow
Parameters:
- o some object to check
Returns:
-
yesOrNo true if it's a cow, false if it's not
Usage:
local exiisCowts = require 'luafp.predicates'.isCow print(isCow('cow') -- true print(isCow('🐮')) -- true print(isCow('Jesse')) -- false