Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,9 @@
unique({1, 2, 3, "a", "b", "c", 2, 3, 4, "b", "c", "d"})
on unique(x)
set R to {}
repeat with i in x
if i is not in R then set end of R to i's contents
end repeat
return R
end unique

View file

@ -0,0 +1,3 @@
{1, 2, 3, {4, 5}} contains {2, 3} --> true
{1, 2, 3, {4, 5}} contains {4, 5} --> false
{1, 2, 3, {4, 5}} contains {{4, 5}} --> true

View file

@ -0,0 +1 @@
3 is in {1, 2, 3, {4, 5}} --> {3} is in {1, 2, 3, {4, 5}} --> true

View file

@ -0,0 +1,10 @@
unique({1, 2, 3, "a", "b", "c", 2, 3, 4, "c", {b:"c"}, {"c"}, "c", "d"})
on unique(x)
set R to {}
repeat with i in x
set i to i's contents
if {i} is not in R then set end of R to i
end repeat
return R
end unique

View file

@ -0,0 +1 @@
{1, 2, 3, "a", "b", "c", 4, {b:"c"}, {"c"}, "d"}

View file

@ -0,0 +1,92 @@
-- CASE-INSENSITIVE UNIQUE ELEMENTS ------------------------------------------
-- nub :: [a] -> [a]
on nub(xs)
-- Eq :: a -> a -> Bool
script Eq
on |λ|(x, y)
ignoring case
x = y
end ignoring
end |λ|
end script
nubBy(Eq, xs)
end nub
-- TEST ----------------------------------------------------------------------
on run
{intercalate(space, ¬
nub(splitOn(space, "4 3 2 8 0 1 9 5 1 7 6 3 9 9 4 2 1 5 3 2"))), ¬
intercalate("", ¬
nub(characters of "abcabc ABCABC"))}
--> {"4 3 2 8 0 1 9 5 7 6", "abc "}
end run
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
tell mReturn(f)
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set v to item i of xs
if |λ|(v, i, xs) then set end of lst to v
end repeat
return lst
end tell
end filter
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn
-- nubBy :: (a -> a -> Bool) -> [a] -> [a]
on nubBy(fnEq, xxs)
set lng to length of xxs
if lng > 1 then
set x to item 1 of xxs
set xs to items 2 thru -1 of xxs
set p to mReturn(fnEq)
-- notEq :: a -> Bool
script notEq
on |λ|(a)
not (p's |λ|(a, x))
end |λ|
end script
{x} & nubBy(fnEq, filter(notEq, xs))
else
xxs
end if
end nubBy
-- splitOn :: Text -> Text -> [Text]
on splitOn(strDelim, strMain)
set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
set lstParts to text items of strMain
set my text item delimiters to dlm
return lstParts
end splitOn

View file

@ -0,0 +1 @@
{"4 3 2 8 0 1 9 5 7 6", "abc "}

View file

@ -0,0 +1,6 @@
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
set aList to {1, 2, 3, "a", "b", "c", 2, 3, 4, "c", {b:"c"}, {"c"}, "c", "d"}
set orderedSet to current application's class "NSOrderedSet"'s orderedSetWithArray:(aList)
return orderedSet's array() as list

View file

@ -0,0 +1 @@
{1, 2, 3, "a", "b", "c", 4, {b:"c"}, {"c"}, "d"}