Hash join: Difference between revisions
→{{header|AppleScript}}: Updated primitives
(→{{header|AppleScript}}: Updated primitives) |
|||
Line 122:
=={{header|AppleScript}}==
{{Trans|JavaScript}}
Native AppleScript records lack introspection, but from Yosemite onwards we can read and write them a little more flexibly through the Foundation classes.
Line 128 ⟶ 127:
<lang AppleScript>use framework "Foundation" -- Yosemite onwards, for record-handling functions
-- HASH JOIN -----------------------------------------------------------------
-- hashJoin :: [Record] -> [Record] -> String -> [Record]
Line 134 ⟶ 135:
script instanceOfjB
on
set strID to keyValue(x, jB)
Line 143 ⟶ 144:
updatedRecord(a, strID, [x])
end if
end
end script
Line 149 ⟶ 150:
script joins
on
set matches to keyValue(M, keyValue(x, jA))
if matches is not missing value then
script concat
on
x & row
end
end script
Line 162 ⟶ 163:
a
end if
end
end script
Line 168 ⟶ 169:
end hashJoin
-- TEST ----------------------------------------------------------------------
on run
set lstA to [¬
Line 189 ⟶ 190:
-- RECORD FUNCTIONS ----------------------------------------------------------
-- keyValue :: String -> Record -> Maybe a
on keyValue(rec, strKey)
set ca to current application
set v to (ca's NSDictionary's dictionaryWithDictionary:rec)'s
objectForKey:strKey
if v is not missing value then
item 1 of ((ca's NSArray's arrayWithObject:v) as list)
Line 211 ⟶ 213:
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- foldl :: (a -> b -> a) -> a -> [b] -> a
Line 219 ⟶ 221:
set lng to length of xs
repeat with i from 1 to lng
set v to
end repeat
return v
Line 231 ⟶ 233:
set lst to {}
repeat with i from 1 to lng
set end of lst to
end repeat
return lst
end tell
end map
-- 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▼
-- Lift 2nd class handler function into 1st class script wrapper
Line 252 ⟶ 246:
else
script
property
end script
end if
end mReturn
▲-- 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</lang>
{{Out}}
<pre>{{age:27, |name|:"Jonah", |character|:"Jonah", nemesis:"Whales"},
Line 266:
{age:28, |name|:"Alan", |character|:"Alan", nemesis:"Ghosts"},
{age:28, |name|:"Alan", |character|:"Alan", nemesis:"Zombies"}}</pre>
=={{header|AWK}}==
<lang AWK>
|